The prepend() methods insert information
before the existing data for a given key. Note that as with the
append() method, the information will be
inserted before the existing binary data stored in the key, which
means that serialization of complex objects may lead to corruption
when using prepend().
| API Call | client.prepend(casunique, key, value) | ||
| Asynchronous | yes | ||
| Description | Prepend a value to an existing key | ||
| Returns | Future<Boolean> (
Asynchronous request value, as Boolean
) | ||
| Arguments | |||
long casunique | Unique value used to verify a key/value combination | ||
String key | Document ID used to identify the value | ||
Object value | Value to be stored | ||
The prepend() inserts information before
the existing data stored in the key/value pair. The
prepend() function requires a CAS value.
For more information on CAS values, see
Section 4.4, “CAS get Methods”.
For example, to prepend a string to an existing key:
CASValue<Object> casv = membase.gets("samplekey"); membase.prepend(casv.getCas(),"samplekey", "prependedstring");
You can check if the append operation succeeded by using the
return Future value:
Future<Boolean> success = membase.prepend(casv.getCas(),"notsamplekey", "prependedstring"); try { if (success.get()) { System.out.printf("Prepend succeeded\n"); } else { System.out.printf("Prepend failed\n"); } } catch (Exception e) { ... }
| API Call | client.prepend(casunique, key, value, transcoder) | ||
| Asynchronous | yes | ||
| Description | Prepend a value to an existing key | ||
| Returns | Future<Boolean> (
Asynchronous request value, as Boolean
) | ||
| Arguments | |||
long casunique | Unique value used to verify a key/value combination | ||
String key | Document ID used to identify the value | ||
Object value | Value to be stored | ||
Transcoder<T> transcoder | Transcoder class to be used to serialize value | ||
The secondary form of the prepend()
method supports the use of a custom transcoder for updating the
key/value pair.