Couchbase C Client  3.3.14
Asynchronous C Client for Couchbase

Detailed Description

Retrieve a document from the cluster

Function Documentation

◆ lcb_cmdget_on_behalf_of()

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

Typedef Documentation

◆ lcb_RESPGET

typedef struct lcb_RESPGET_ lcb_RESPGET

Command for retrieving a single item.

See also
lcb_get()
lcb_RESPGET

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
Stability
Committed

Spool a single get operation

Parameters
instancethe handle
cookiea pointer to be associated with the command
cmdthe command structure
Returns
LCB_SUCCESS if successful, an error code otherwise
Request
lcb_CMDGET* cmd;
lcb_cmdget_create(&cmd);
lcb_cmdget_key(cmd, "Hello", 5);
lcb_get(instance, cookie, cmd);
Response
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.
lcb_STATUS
Error codes returned by the library.
Definition error.h:213
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)
@ LCB_CALLBACK_GET
lcb_get()
Definition couchbase.h:471
Errors
  • ::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.