The set() operations store a value into
Couchbase or Memcached using the specified key and value. The
value is stored against the specified key, even if the key already
exists and has data. This operation overwrites the existing with
the new data. The store operation in this case is asynchronous.
| API Call | client.set(key, expiry, value) | ||
| Asynchronous | yes | ||
| Description | Store a value using the specified key, whether the key already exists or not. Will overwrite a value if the given key/value already exists. | ||
| Returns | OperationFuture<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 first form of the set() method stores the
key, sets the expiry (use 0 for no expiry), and the corresponding
object value using the built in transcoder for serialization.
The simplest form of the command is:
client.set("someKey", 3600, someObject);
The Boolean return value from the asynchronous
operation return value will be true if the value was stored. For
example:
OperationFuture<Boolean> setOp = client.set("someKey",0,"astring"); System.out.printf("Result was %b",setOp.get());
| API Call | client.set(key, expiry, value, transcoder) | ||
| Asynchronous | yes | ||
| Description | Store a value using the specified key and a custom transcoder. | ||
| Returns | OperationFuture<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 | ||
The second form of the set() method 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)”.