Atomic counter operations.
Increment or decrement a numerical item within the cluster.
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.
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;
- Parameters
-
instance | the handle to lcb |
command_cookie | A cookie passed to all of the notifications from this command |
num | the total number of elements in the commands array |
commands | the array containing the items to operate on |
- Returns
- Status of the operation.
- Stability
- Committed:
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 |
union lcb_arithmetic_cmd_t.v |
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
-
instance | the instance performing the operation |
cookie | the cookie associated with with the command |
error | The status of the operation |
resp | More information about the operation (only key and nkey is valid if error != LCB_SUCCESS) |
- Stability
- Committed: