Manipulate the numeric content of a document
Counter operations treat the document being accessed as a numeric value (the document should contain a parseable integer as its content). This value may then be incremented or decremented.
◆ lcb_cmdcounter_on_behalf_of()
lcb_STATUS lcb_cmdcounter_on_behalf_of |
( |
lcb_CMDCOUNTER * | cmd, |
|
|
const char * | data, |
|
|
size_t | data_len ) |
- Stability
- Internal
- Internal: This should never be used and is not supported.
◆ lcb_cmdcounter_on_behalf_of_extra_privilege()
lcb_STATUS lcb_cmdcounter_on_behalf_of_extra_privilege |
( |
lcb_CMDCOUNTER * | cmd, |
|
|
const char * | privilege, |
|
|
size_t | privilege_len ) |
- Stability
- Internal
- Internal: This should never be used and is not supported.
◆ lcb_RESPCOUNTER
Schedule single counter operation.
- Stability
- Committed
- Parameters
-
instance | the instance |
cookie | the pointer to associate with the request |
cmd | the command to use |
- Returns
- LCB_SUCCESS on success, other error on failure
- Request
lcb_CMDCOUNTER* cmd;
lcb_cmdcounter_create(&cmd);
lcb_cmdcounter_key(cmd, "counter", strlen("counter"));
lcb_cmdcounter_delta(cmd, 1);
lcb_cmdcounter_value(cmd, 42);
lcb_cmdcounter_expiry(cmd, 300);
lcb_counter(instance, NULL, cmd);
lcb_STATUS lcb_wait(lcb_INSTANCE *instance, lcb_WAITFLAGS flags)
Wait for completion of scheduled operations.
@ LCB_WAIT_NOCHECK
Do not check pending operations before running the event loop.
Definition couchbase.h:1870
- Response
void counter_cb(
lcb_INSTANCE *instance,
int cbtype,
const lcb_RESPBASE *rb)
{
if (rc == LCB_SUCCESS) {
char* key;
size_t key_len;
uint64_t value;
lcb_respcounter_value(resp, &value);
lcb_respcounter_key(resp, &key, &key_len);
printf("Incremented counter for %.*s. Current value %llu\n",
key_len, key, value);
}
}
struct lcb_RESPCOUNTER_ lcb_RESPCOUNTER
Schedule single counter operation.
Definition couchbase.h:1201
lcb_STATUS
Error codes returned by the library.
Definition error.h:213
struct lcb_st lcb_INSTANCE
Library handle representing a connection to a cluster and its data buckets.
Definition couchbase.h:35
lcb_RESPCALLBACK lcb_install_callback(lcb_INSTANCE *instance, int cbtype, lcb_RESPCALLBACK cb)
- Callback Errors
- In addition to generic errors, the following errors may be returned in the callback (via lcb_respcounter_status):
- ::LCB_ERR_DOCUMENT_NOT_FOUND if the counter doesn't exist
- ::LCB_ERR_INVALID_DELTA if the existing document's content could not be parsed as a number by the server.