The replace methods update an existing
key/value pair in the database. If the specified key does not
exist, then the operation will fail.
| API Call | object.replace(key, value [, ruby-replace-options ]) | ||
| Asynchronous | no | ||
| Description | Update an existing key with a new value | ||
| Returns | fixnum (
The CAS value for the object stored. A fixed number
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
object value | Value to be stored | ||
hash ruby-replace-options | Hash of options containing key/value pairs | ||
| Exceptions | |||
Couchbase::Error::Connect | Exception object specifying failure to connect to a node. | ||
Couchbase::Error::KeyExists | Exception object indicating the CAS value does not match the one for the record already on the server. | ||
Couchbase::Error::NotFound | Exception object specifying a given key cannot be found in datastore. | ||
The first form of the replace method
updates an existing value setting while supporting the explicit
setting of the expiry time on the item. For example to update the
samplekey:
couchbase.replace("samplekey","updatedvalue",0);