Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library Ruby 1.0
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
5 Ruby — Storage Operations
Chapter Sections
Chapters

5.2. Replace Operations

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 Callobject.replace(key, value [, ruby-replace-options ])
Asynchronousno
Description Update an existing key with a new value
Returnsfixnum ( 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);