The add() method adds a value to the
database with the specified key, but will fail if the key already
exists in the database.
| API Call | client.add(key, expiry, value) | ||
| Asynchronous | yes | ||
| Description | Add a value with the specified key that does not already exist. Will fail if the key/value pair already exist. | ||
| Returns | Future<Boolean> (
Asynchronous request value, as Boolean
) | ||
| Arguments | |||
String key | Document ID used to identify the value | ||
int expiry | Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch). | ||
Object value | Value to be stored | ||
The add() method adds a value to the
database using the specified key.
client.add("someKey", 0, someObject);Unlike Section 6.2, “Set Operations” the operation can fail (and return false) if the specified key already exist.
For example, the first operation in the example below may complete if the key does not already exist, but the second operation will always fail as the first operation will have set the key:
OperationFuture<Boolean> addOp = client.add("someKey",0,"astring"); System.out.printf("Result was %b",addOp.get()); addOp = client.add("someKey",0,"anotherstring"); System.out.printf("Result was %b",addOp.get());
| API Call | client.add(key, expiry, value, transcoder) | ||
| Asynchronous | yes | ||
| Description | Add a value with the specified key that does not already exist. Will fail if the key/value pair already exist. | ||
| Returns | Future<Boolean> (
Asynchronous request value, as Boolean
) | ||
| Arguments | |||
String key | Document ID used to identify the value | ||
int expiry | Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch). | ||
Object value | Value to be stored | ||
Transcoder<T> transcoder | Transcoder class to be used to serialize value | ||
This method is identical to the add()
method, but supports the use of a custom transcoder for
serialization of the object value. For more information on
transcoding, see
Section 4.3, “Object Serialization (Transcoding)”.