Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | SDKs | SDKs

PHP Methods dealing with CAS

1 reply [Last post]
  • Login or register to post comments
Wed, 05/23/2012 - 15:44
phpboi
Offline
Joined: 05/23/2012
Groups: None

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?

Top
  • Login or register to post comments
Wed, 06/13/2012 - 19:38
BigBlueHat
Offline
Joined: 01/28/2011
Groups: None

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:

$cas = 0;
$cb->getDelayed(array('key_name'), true, function($cb, $data) use (&$cas) { $cas = $data['cas']; }));
print_r($cas); // outputs the returned 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:

Array
(
    [key] => key_name
    [value] => aw yeah!
    [cas] => 6413970294305718272
)

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

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker