Couchbase C Client  2.4.4
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:

Data Structure Documentation

struct lcb_ARITHCMDv0

Command structure for arithmetic operations This is contained within the lcb_arithmetic_cmd_t structure.

Data Fields
const void * key
lcb_SIZE nkey
lcb_time_t exptime Expiration time for the item.

Note this is only valid if create is set to true.

int create If the item does not exist on the server, set this to true to force the creation of the item.

Otherwise the operation will fail with LCB_KEY_ENOENT

lcb_S64 delta This number will be added to the current value on the server; if this is negative then the current value will be decremented; if positive then the current value will be incremented.

On the server, the counter value is a 64 bit unsigned integer, whose maximum value is UINT64_MAX If an integer overflow occurs as a result of adding the delta value to the existing value on the server, then the value on the server will wrap around; thus for example, if the existing value was UINT64_MAX-1 and delta was supplied as 2, the new value would be 1.

lcb_U64 initial If the create field is true, this is the initial value for the counter iff the item does not yet exist.
struct lcb_arithmetic_cmd_t

Wrapper structure for lcb_ARITHCMDv0.

Data Fields
int version
union lcb_arithmetic_cmd_t v Wrapper union for lcb_ARITHCMDv0.
union lcb_arithmetic_cmd_t.v

Wrapper union for lcb_ARITHCMDv0.

Data Fields
lcb_ARITHCMDv0 v0 Fill this structure.

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: