Name

lcb_arithmetic — Perform arithmetic operations

Synopsis

cc [ flag … ] file… -lcouchbase [ library … ]

#include <libcouchbase/couchbase.h>
lcb_error_t lcb_arithmetic(lcb_t instance,
                           const void *command_cookie,
                           lcb_size_t num,
                           const lcb_arithmetic_cmd_t *const *commands);

DESCRIPTION

lcb_arithmetic() is used to perform a arithmetic operations on a document’s value. If the library instance is using asynchronous mode (the default) this operation will return immediately and schedule the operations to be executed by the event loop, otherwise it will block until all commands are executed. command_cookie is is an opaque field that will be provided to the callback function. num is the number of entries in the commands array.

lcb_arithmetic_cmd_t is a structure defined in <libcouchbase/arguments.h>:

typedef struct lcb_arithmetic_cmd_st {
         int version;              /* The enty in "v" to use */
         union {
            struct {
               const void *key;    /* The key this response belongs to */
               lcb_size_t nkey;    /* The number of bytes in the key */
               lcb_time_t exptime; /* The documents expiry time */
               int create;         /* create non-existent documents */
               lcb_int64_t delta;  /* amount to add/subtract */
               lcb_uint64_t initial; /* initial value if creating */
               const void *hashkey; /* hash key if != key */
               lcb_size_t nhashkey; /* number of bytes in hash key */
            } v0;
         } v;
      };

Please note that using an alternate key for hashing may lead to an unbalanced cluster if the key does not hash evenly with a crc32.

Upon completion the arithmetic callback as set by lcb_set_arithmetic_callback is called.

RETURN VALUES

lcb_arithmetic() returns the LCB_SUCCESS on success, or a specific error code upon failure. See lcb_strerror(3couchbase) for more information.

EXAMPLES

Example 1: Query the current callback

#include <libcouchbase/couchbase.h>
...
lcb_t instance;
...
lcb_arithmetic_cmd_t *arithmetic = calloc(1, sizeof(*arithmetic));
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;
lcb_arithmetic_cmd_t* commands[] = { arithmetic };
lcb_arithmetic(instance, NULL, 1, commands);
...

ATTRIBUTES

See lcb_attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE

Interface Stability

Committed

MT-Level

MT-Safe

COPYRIGHT

Copyright 2010-2013 Couchbase, Inc.

SEE ALSO

Learn more at http://www.couchbase.com/communities/c.

libcouchbase(3lib), lcb_get_arithmetic_callback(3couchbase), lcb_set_arithmetic_callback(3couchbase), lcb_attributes(5)