Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: Java 1.0
Community Wiki and Resources
Wiki: Java Client Library
Download Client Library
JavaDoc
Java Client Library
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
6 Store Operations
Chapter Sections
Chapters

6.2. Set Operations

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.

API Callclient.set(key, expiry, value)
Asynchronousyes
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.
ReturnsOperationFuture<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 will be true if the value was stored. For example:

OperationFuture<Boolean> setOp = membase.set("someKey",0,"astring");
System.out.printf("Result was %b",setOp.get());
API Callclient.set(key, expiry, value, transcoder)
Asynchronousyes
Description Store a value using the specified key and a custom transcoder.
ReturnsOperationFuture<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 set() 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)”.