Couchbase C Client  2.4.2
Arithmetic/Counter operations

Detailed Description

Atomic counter operations.

Increment or decrement a numerical item within the cluster.

Functions

lcb_arithmetic_callback lcb_set_arithmetic_callback (lcb_t, lcb_arithmetic_callback)
 
lcb_error_t lcb_arithmetic (lcb_t instance, const void *command_cookie, lcb_SIZE num, const lcb_arithmetic_cmd_t *const *commands)
 Perform arithmetic operation on a keys value. More...
 

Typedefs

typedef void(* lcb_arithmetic_callback) (lcb_t instance, const void *cookie, lcb_error_t error, const lcb_arithmetic_resp_t *resp)
 The callback function for an arithmetic request. More...
 

Function Documentation

lcb_arithmetic_callback lcb_set_arithmetic_callback ( lcb_t  ,
lcb_arithmetic_callback   
)
Stability
Committed:
lcb_error_t lcb_arithmetic ( lcb_t  instance,
const void *  command_cookie,
lcb_SIZE  num,
const lcb_arithmetic_cmd_t *const *  commands 
)

Perform arithmetic operation on a keys value.

You should initialize the key, nkey and expiration member in the lcb_item_st structure for the keys to update. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch). All other members should be set to zero.

lcb_arithmetic_cmd_t *arithmetic = calloc(1, sizeof(*arithmetic));
arithmetic->version = 0;
arithmetic->v.v0.key = "counter";
arithmetic->v.v0.nkey = strlen(arithmetic->v.v0.key);
arithmetic->v.v0.initial = 0x666;
arithmetic->v.v0.create = 1;
arithmetic->v.v0.delta = 1;
lcb_arithmetic_cmd_t* commands[] = { arithmetic };
lcb_arithmetic(instance, NULL, 1, commands);
Parameters
instancethe handle to lcb
command_cookieA cookie passed to all of the notifications from this command
numthe total number of elements in the commands array
commandsthe array containing the items to operate on
Returns
Status of the operation.
Stability
Committed:

Typedef Documentation

typedef void(* lcb_arithmetic_callback) (lcb_t instance, const void *cookie, lcb_error_t error, const lcb_arithmetic_resp_t *resp)

The callback function for an arithmetic request.

Parameters
instancethe instance performing the operation
cookiethe cookie associated with with the command
errorThe status of the operation
respMore information about the operation (only key and nkey is valid if error != LCB_SUCCESS)
Stability
Committed: