| API Call | client.set(key, expiry, value, persistto) | ||
| Asynchronous | yes | ||
| Description | Store a value using the specified key and observe it being persisted on master and more node(s). | ||
| 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 | ||
enum persistto | Specify the number of nodes on which the document must be persisted to before returning. | ||
| API Call | client.set(key, expiry, value, replicateto) | ||
| Asynchronous | yes | ||
| Description | Store a value using the specified key and observe it being replicated to one or more node(s). | ||
| 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 | ||
enum replicateto | Specify the number of nodes on which the document must be replicated to before returning | ||
| API Call | client.set(key, expiry, value, persistto, replicateto) | ||
| Asynchronous | yes | ||
| Description | Store a value using the specified key and observe it being persisted on master and more node(s) and being replicated to one or more node(s). | ||
| 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 | ||
enum persistto | Specify the number of nodes on which the document must be persisted to before returning. | ||
enum replicateto | Specify the number of nodes on which the document must be replicated to before returning | ||
This method is identical to the set()
method, but supports the ability to observe the persistence on the
master and replicas and the propagation to the replicas. Using
these methods above, it's possible to set the persistence
requirements for the data on the nodes.
The persistence requirements can be specified in terms of how the
data should be persisted on the master and the replicas using
PeristTo and how the data should be
propagated to the replicas using
ReplicateTo respectively.
The client library will poll the server until the persistence requirements are met. The method will return FALSE if the requirments are impossible to meet based on the configuration (inadequate number of replicas) or even after a set amount of retries the persistence requirments could not be met.
The program snippet below illustrates how to specify a requirement that the data should be persisted on 4 nodes (master and three replicas).
// Perist to all four nodes including master OperationFuture<Boolean> setOp = c.set("key", 0, "value", PersistTo.FOUR); System.out.printf("Result was %b", setOp.get());
The peristence requirements can be specified for both the master and replicas. In the case above, it's required that the key and value is persisted on all the 4 nodes (including replicas).
In the following, the requirement is specified as requiring persistence to the master and propagation of the data to the three replicas. This requirment is weaker than requring the data to be persisted on all four nodes including the three replicas.
// Perist to master and propagate the data to three replicas OperationFuture<Boolean> setOp = c.set("key", 0, "value", PersistTo.MASTER, ReplicateTo.THREE); System.out.printf("Result was %b", setOp.get());
Similar requirements can used with the add() and replace() mutation operations.