PHP Methods dealing with CAS
Wed, 05/23/2012 - 15:44
I'm at a loss for how to use a CAS token with PHP methods.
I think my main hangup is how to get the CAS token to begin with.
I consulted the manual: http://www.couchbase.com/docs/couchbase-sdk-php-1.0/api-reference-summar...
I googled around quite a bit and poked through these forums and can't find the answer.
I'm using version 1.0.3 of the couchbase PHP extension.
I've tried using the method getDelayed: http://www.couchbase.com/docs/couchbase-sdk-php-1.0/api-reference-retrie...
This method does not seem to return anything useful.
Can anybody provide some sample method calls for setting/getting values involving a CAS token in PHP?
Hey phpboi,
First, sorry for the slow reply. Hopefully this answer will get you back on the right track.
Second, it looks like you've found a bug with our documentation which I've reported [1].
getDelayed() actually returns a Boolean and is meant to be used with a callback function. If you're using PHP 5.3+, this code should work for retrieving the $cas value:
Additionally, the $data array in that callback contains the key and value for the item you're getting. So it looks something like this if you print_r() it:
From there you can use the cas value with cas() to conditionally update the item if the cas value matches.
Hope that helps!
[1] http://www.couchbase.com/issues/browse/PCBC-72