Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

couchbase - how to use getandlock with php

Tags:

php

couchbase

I am using couchbase with php as a temporary database, There will be multiple scripts running simultaneously to fetch and update the value of an object, i want to protect the object from having wrong value at any time, thus implementing lock over object.

I tried to Implemented couchbase getandlock method but the documentation does not clearly how to use it.

Any help will be appreciated.

like image 573
Dragon Avatar asked Feb 02 '26 23:02

Dragon


1 Answers

What you'll want to use is the CAS feature of Couchbase. The official documentation describes it well:

This operation is also known as a check-and-set method; it enables you to update information only if a unique identifier matches the identifier for the document you want to change. This identifier, called a CAS value or ID, prevents an application from updating values in the database that may have changed since the application originally obtained the value.

Link to official doc -> http://docs.couchbase.com/couchbase-devguide-2.5/#check-and-set-cas

You can see an example gist here of using PHP and CAS:

https://gist.github.com/3155132/2301591fa9d2dddbf3c2578ad1369703493c5aef

like image 73
scalabilitysolved Avatar answered Feb 05 '26 13:02

scalabilitysolved



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!