Couchbase C Client  3.3.2
Asynchronous C Client for Couchbase

Detailed Description

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_STATUS lcb_respcounter_status (const lcb_RESPCOUNTER *resp)
lcb_STATUS lcb_respcounter_error_context (const lcb_RESPCOUNTER *resp, const lcb_KEY_VALUE_ERROR_CONTEXT **ctx)
lcb_STATUS lcb_respcounter_cookie (const lcb_RESPCOUNTER *resp, void **cookie)
lcb_STATUS lcb_respcounter_cas (const lcb_RESPCOUNTER *resp, uint64_t *cas)
lcb_STATUS lcb_respcounter_key (const lcb_RESPCOUNTER *resp, const char **key, size_t *key_len)
lcb_STATUS lcb_respcounter_mutation_token (const lcb_RESPCOUNTER *resp, lcb_MUTATION_TOKEN *token)
lcb_STATUS lcb_respcounter_value (const lcb_RESPCOUNTER *resp, uint64_t *value)
lcb_STATUS lcb_cmdcounter_create (lcb_CMDCOUNTER **cmd)
lcb_STATUS lcb_cmdcounter_destroy (lcb_CMDCOUNTER *cmd)
lcb_STATUS lcb_cmdcounter_parent_span (lcb_CMDCOUNTER *cmd, lcbtrace_SPAN *span)
lcb_STATUS lcb_cmdcounter_collection (lcb_CMDCOUNTER *cmd, const char *scope, size_t scope_len, const char *collection, size_t collection_len)
lcb_STATUS lcb_cmdcounter_key (lcb_CMDCOUNTER *cmd, const char *key, size_t key_len)
lcb_STATUS lcb_cmdcounter_expiry (lcb_CMDCOUNTER *cmd, uint32_t expiration)
lcb_STATUS lcb_cmdcounter_delta (lcb_CMDCOUNTER *cmd, int64_t number)
lcb_STATUS lcb_cmdcounter_initial (lcb_CMDCOUNTER *cmd, uint64_t number)
lcb_STATUS lcb_cmdcounter_durability (lcb_CMDCOUNTER *cmd, lcb_DURABILITY_LEVEL level)
 LCB_DEPRECATED2 (1 lcb_STATUS lcb_cmdcounter_cas(lcb_CMDCOUNTER *cmd, uint64_t cas), "CAS is not applicable to arithmetic operations")
lcb_STATUS lcb_cmdcounter_timeout (lcb_CMDCOUNTER *cmd, uint32_t timeout)
lcb_STATUS lcb_cmdcounter_on_behalf_of (lcb_CMDCOUNTER *cmd, const char *data, size_t data_len)
lcb_STATUS lcb_cmdcounter_on_behalf_of_extra_privilege (lcb_CMDCOUNTER *cmd, const char *privilege, size_t privilege_len)
lcb_STATUS lcb_counter (lcb_INSTANCE *instance, void *cookie, const lcb_CMDCOUNTER *cmd)


typedef struct lcb_RESPCOUNTER_ lcb_RESPCOUNTER
 Schedule single counter operation. More...
typedef struct lcb_CMDCOUNTER_ lcb_CMDCOUNTER

Function Documentation

◆ lcb_cmdcounter_on_behalf_of()

lcb_STATUS lcb_cmdcounter_on_behalf_of ( lcb_CMDCOUNTER *  cmd,
const char *  data,
size_t  data_len 
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 
Internal: This should never be used and is not supported.

Typedef Documentation


typedef struct lcb_RESPCOUNTER_ lcb_RESPCOUNTER

Schedule single counter operation.

instancethe instance
cookiethe pointer to associate with the request
cmdthe command to use
LCB_SUCCESS on success, other error on failure
lcb_CMDCOUNTER* cmd;
lcb_cmdcounter_key(cmd, "counter", strlen("counter"));
lcb_cmdcounter_delta(cmd, 1); // Increment by one
lcb_cmdcounter_value(cmd, 42); // Default value is 42 if it does not exist
lcb_cmdcounter_expiry(cmd, 300); // Expire in 5 minutes
lcb_counter(instance, NULL, cmd);
lcb_STATUS lcb_wait(lcb_INSTANCE *instance, lcb_WAITFLAGS flags)
Wait for completion of scheduled operations.
Do not check pending operations before running the event loop.
Definition: couchbase.h:1863
lcb_install_callback(instance, LCB_CALLBACKTYPE_COUNTER, counter_cb);
void counter_cb(lcb_INSTANCE *instance, int cbtype, const lcb_RESPBASE *rb)
const lcb_RESPCOUNTER *resp = (const lcb_RESPCOUNTER *)rb;
lcb_STATUS = lcb_respcounter_status(resp);
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);
Schedule single counter operation.
Definition: couchbase.h:1194
Error codes returned by the library.
Definition: error.h:212
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.