The append() methods allow you to add
information to an existing key/value pair in the database. You can
use this to add information to a string or other data after the
existing data.
The append() methods append raw
serialized data on to the end of the existing data in the key. If
you have previously stored a serialized object into Couchbase and
then use append, the content of the serialized object will not be
extended. For example, adding an Array of
integers into the database, and then using
append() to add another integer will
result in the key referring to a serialized version of the array,
immediately followed by a serialized version of the integer. It
will not contain an updated array with the new integer appended to
it. De-serialization of objects that have had data appended may
result in data corruption.
| API Call | client.append(casunique, key, value) | ||
| Asynchronous | no | ||
| Description | Append a value to an existing key | ||
| Returns | Object (
Binary object
) | ||
| 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 append() appends information to the
end of an existing key/value pair. The
append() function requires a CAS value.
For more information on CAS values, see
Section 7.4, “CAS get Methods”.
For example, to append a string to an existing key:
CASValue<Object> casv = client.gets("samplekey"); client.append(casv.getCas(),"samplekey", "appendedstring");
You can check if the append operation succeeded by using the
return OperationFuture value:
OperationFuture<Boolean> appendOp = client.append(casv.getCas(),"notsamplekey", "appendedstring"); try { if (appendOp.get().booleanValue()) { System.out.printf("Append succeeded\n"); } else { System.out.printf("Append failed\n"); } } catch (Exception e) { ... }
| API Call | client.append(casunique, key, value, transcoder) | ||
| Asynchronous | no | ||
| Description | Append a value to an existing key | ||
| Returns | Object (
Binary object
) | ||
| 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 second form of the append() method
supports the use of custom transcoder.