The increment methods enable you to increase a given stored integer value. These are the incremental equivalent of the decrement operations and work on the same basis; updating the value of a key if it can be parsed to an integer. The update operation occurs on the server and is provided at the protocol level. This simplifies what would otherwise be a two-stage get and set operation.
| API Call | object.incr(key [, offset ] [, defaultvalue ] [, expiry ]) | ||
| Asynchronous | no | ||
| Description | Increment the value of an existing numeric key. Couchbase Server stores numbers as unsigned numbers, therefore if you try to increment an existing negative number, it will cause an integer overflow and return a non-logical numeric result. If a key does not exist, this method will initialize it with the zero or a specified value. | ||
| Returns | object (
Binary object
) | ||
| Arguments | |||
key | Document ID used to identify the value | ||
offset | Integer offset value to increment/decrement (default 1) | ||
defaultvalue | Value to be stored if key does not already exist | ||
expiry | Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch). | ||
The first form of the incr() method
accepts the keyname and offset (increment) value to be used when
increasing the server-side integer. For example, to increment the
server integer dlcounter by 5:
membase.incr("dlcounter",5);The return value is the updated value of the specified key.