Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: Java 1.0
Community Wiki and Resources
Wiki: Java Client Library
Download Client Library
JavaDoc
Java Client Library
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
7 Retrieve Operations
Chapter Sections
Chapters

7.4. CAS get Methods

The gets() methods obtain a CAS value for a given key. The CAS value is used in combination with the corresponding Check-and-Set methods when updating a value. For example, you can use the CAS value with the append() operation to update a value only if the CAS value you supply matches. For more information see Section 8.1, “Append Methods” and Section 8.3, “Check-and-Set Methods”.

API Callclient.gets(key)
Asynchronousno
Description Get single key value with CAS value
ReturnsCASValue ( Check and set object )
Arguments 
String key Document ID used to identify the value

The gets() method obtains a CASValue for a given key. The CASValue holds the CAS to be used when performing a Check-And-Set operation, and the corresponding value for the given key.

For example, to obtain the CAS and value for the key someKey:

CASValue status = client.gets("someKey");
System.out.printf("CAS is %s\n",status.getCas());
System.out.printf("Result was %s\n",status.getValue());

The CAS value can be used in a CAS call such as append():

client.append(status.getCas(),"someKey", "appendedstring");
API Callclient.gets(key, transcoder)
Asynchronousno
Description Get single key value with CAS value
ReturnsCASValue ( Check and set object )
Arguments 
String key Document ID used to identify the value
Transcoder<T> transcoder Transcoder class to be used to serialize value

The second form of the gets() method supports the use of a custom transcoder.

API Callclient.asyncGets(key)
Asynchronousyes
Description Get single key value with CAS value
ReturnsFuture<CASValue<Object>> ( Asynchronous request value, as CASValue, as Object )
Arguments 
String key Document ID used to identify the value

The asyncGets() method obtains the CASValue object for a stored value against the specified key, without requiring an explicit wait for the returned value.

For example:

Future<CASValue<Object>> future = client.asyncGets("someKey");

System.out.printf("CAS is %s\n",future.get(5,TimeUnit.SECONDS).getCas());

Note that you have to extract the CASValue from the Future response, and then the CAS value from the corresponding object. This is performed here in a single statement.

API Callclient.asyncGets(key, transcoder)
Asynchronousyes
Description Get single key value with CAS value
ReturnsFuture<CASValue<T>> ( Asynchronous request value, as CASValue as Transcoded object )
Arguments 
String key Document ID used to identify the value
Transcoder<T> transcoder Transcoder class to be used to serialize value

The final form of the asyncGets() method supports the use of a custom transcoder.