Couchbase C Client  3.3.2
Asynchronous C Client for Couchbase

Detailed Description

Retrieve a document from the cluster.


lcb_STATUS lcb_respget_status (const lcb_RESPGET *resp)
lcb_STATUS lcb_respget_error_context (const lcb_RESPGET *resp, const lcb_KEY_VALUE_ERROR_CONTEXT **ctx)
lcb_STATUS lcb_respget_cookie (const lcb_RESPGET *resp, void **cookie)
lcb_STATUS lcb_respget_cas (const lcb_RESPGET *resp, uint64_t *cas)
lcb_STATUS lcb_respget_datatype (const lcb_RESPGET *resp, uint8_t *datatype)
lcb_STATUS lcb_respget_flags (const lcb_RESPGET *resp, uint32_t *flags)
lcb_STATUS lcb_respget_key (const lcb_RESPGET *resp, const char **key, size_t *key_len)
lcb_STATUS lcb_respget_value (const lcb_RESPGET *resp, const char **value, size_t *value_len)
lcb_STATUS lcb_cmdget_create (lcb_CMDGET **cmd)
lcb_STATUS lcb_cmdget_destroy (lcb_CMDGET *cmd)
lcb_STATUS lcb_cmdget_parent_span (lcb_CMDGET *cmd, lcbtrace_SPAN *span)
lcb_STATUS lcb_cmdget_collection (lcb_CMDGET *cmd, const char *scope, size_t scope_len, const char *collection, size_t collection_len)
lcb_STATUS lcb_cmdget_key (lcb_CMDGET *cmd, const char *key, size_t key_len)
lcb_STATUS lcb_cmdget_expiry (lcb_CMDGET *cmd, uint32_t expiration)
lcb_STATUS lcb_cmdget_locktime (lcb_CMDGET *cmd, uint32_t duration)
lcb_STATUS lcb_cmdget_timeout (lcb_CMDGET *cmd, uint32_t timeout)
lcb_STATUS lcb_cmdget_on_behalf_of (lcb_CMDGET *cmd, const char *data, size_t data_len)
lcb_STATUS lcb_cmdget_on_behalf_of_extra_privilege (lcb_CMDGET *cmd, const char *privilege, size_t privilege_len)
lcb_STATUS lcb_get (lcb_INSTANCE *instance, void *cookie, const lcb_CMDGET *cmd)


typedef struct lcb_RESPGET_ lcb_RESPGET
 Command for retrieving a single item. More...
typedef struct lcb_CMDGET_ lcb_CMDGET

Function Documentation

◆ lcb_cmdget_on_behalf_of()

lcb_STATUS lcb_cmdget_on_behalf_of ( lcb_CMDGET *  cmd,
const char *  data,
size_t  data_len 
Internal: This should never be used and is not supported.

◆ lcb_cmdget_on_behalf_of_extra_privilege()

lcb_STATUS lcb_cmdget_on_behalf_of_extra_privilege ( lcb_CMDGET *  cmd,
const char *  privilege,
size_t  privilege_len 
Internal: This should never be used and is not supported.

Typedef Documentation


typedef struct lcb_RESPGET_ lcb_RESPGET

Command for retrieving a single item.

See also

Use of the exptime field

  • Get And Touch:

    It is possible to retrieve an item and concurrently modify its expiration time (thus keeping it "alive"). The item's expiry time can be set by calling #lcb_cmdget_expiry.

  • Lock Calling #lcb_cmdget_locktime will set the time the lock should be held for

Spool a single get operation

instancethe handle
cookiea pointer to be associated with the command
cmdthe command structure
LCB_SUCCESS if successful, an error code otherwise
lcb_CMDGET* cmd;
lcb_cmdget_key(cmd, "Hello", 5);
lcb_get(instance, cookie, cmd);
lcb_install_callback(instance, LCB_CALLBACK_GET, get_callback);
static void get_callback(lcb_INSTANCE *instance, int cbtype, const lcb_RESPBASE *rb) {
const lcb_RESPGET *resp = (const lcb_RESPGET*)rb;
char* key;
char* value;
size_t key_len;
size_t value_len;
uint64_t cas;
uint32_t flags;
lcb_respget_key(resp, &key, &key_len);
printf("Got response for key: %.*s\n", key_len, key);
lcb_STATUS rc = lcb_respget_status(resp);
if (rc != LCB_SUCCESS) {
printf("Couldn't get item: %s\n", lcb_strerror_short(rc));
} else {
lcb_respget_cas(resp, &cas);
lcb_respget_value(resp, &value, &value_len);
lcb_respget_flags(resp, &flags);
printf("Got value: %.*s\n", value_len, value);
printf("Got CAS: 0x%llx\n", cas);
printf("Got item/formatting flags: 0x%x\n", flags);
LCB_INTERNAL_API const char * lcb_strerror_short(lcb_STATUS error)
Get a shorter textual description of an error message.
Error codes returned by the library.
Definition: error.h:212
struct lcb_RESPGET_ lcb_RESPGET
Command for retrieving a single item.
Definition: couchbase.h:687
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)
Definition: couchbase.h:471
  • ::LCB_ERR_DOCUMENT_NOT_FOUND if the item does not exist in the cluster
  • ::LCB_ERR_TEMPORARY_FAILURE if the lcb_cmdget_locktime was set but the item was already locked. Note that this error may also be returned (as a generic error) if there is a resource constraint within the server itself.