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 5.1, “Append Methods” and
Section 5.3, “Check-and-Set Methods”.
| API Call | client.gets(key) | ||
| Asynchronous | no | ||
| Description | Get single key value with CAS value | ||
| Returns | CASValue (
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 = membase.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():
membase.append(status.getCas(),"someKey", "appendedstring");| API Call | client.gets(key, transcoder) | ||
| Asynchronous | no | ||
| Description | Get single key value with CAS value | ||
| Returns | CASValue (
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 Call | client.asyncGets(key) | ||
| Asynchronous | yes | ||
| Description | Get single key value with CAS value | ||
| Returns | Future<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 = membase.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 Call | client.asyncGets(key, transcoder) | ||
| Asynchronous | yes | ||
| Description | Get single key value with CAS value | ||
| Returns | Future<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.