Functions that affect the database and the cache. More...
Functions | |
ssize_t | nmdb_get (nmdb_t *db, const unsigned char *key, size_t ksize, unsigned char *val, size_t vsize) |
Get the value associated with a key. | |
int | nmdb_set (nmdb_t *db, const unsigned char *key, size_t ksize, const unsigned char *val, size_t vsize) |
Set the value associated with a key. | |
int | nmdb_set_sync (nmdb_t *db, const unsigned char *key, size_t ksize, const unsigned char *val, size_t vsize) |
Set the value associated with a key, synchronously. | |
int | nmdb_del (nmdb_t *db, const unsigned char *key, size_t ksize) |
Delete a key. | |
int | nmdb_del_sync (nmdb_t *db, const unsigned char *key, size_t ksize) |
Delete a key synchronously. | |
int | nmdb_cas (nmdb_t *db, const unsigned char *key, size_t ksize, const unsigned char *oldval, size_t ovsize, const unsigned char *newval, size_t nvsize) |
Perform an atomic compare-and-swap. | |
int | nmdb_incr (nmdb_t *db, const unsigned char *key, size_t ksize, int64_t increment, int64_t *newval) |
Atomically increment the value associated with a key. |
Functions that affect the database and the cache.
ssize_t nmdb_get | ( | nmdb_t * | db, | |
const unsigned char * | key, | |||
size_t | ksize, | |||
unsigned char * | val, | |||
size_t | vsize | |||
) |
Get the value associated with a key.
db | connection instance. | |
key | the key. | |
ksize | the key size. | |
[out] | val | buffer where the value will be stored. |
vsize | size of the value buffer. |
int nmdb_set | ( | nmdb_t * | db, | |
const unsigned char * | key, | |||
size_t | ksize, | |||
const unsigned char * | val, | |||
size_t | vsize | |||
) |
Set the value associated with a key.
It returns after the command has been acknowledged by the server, but does not wait for the database to confirm it. In any case, further GET requests will return this value, even if this set has not reached the backend yet.
db | connection instance. | |
key | the key. | |
ksize | the key size. | |
val | the value | |
vsize | size of the value. |
int nmdb_set_sync | ( | nmdb_t * | db, | |
const unsigned char * | key, | |||
size_t | ksize, | |||
const unsigned char * | val, | |||
size_t | vsize | |||
) |
Set the value associated with a key, synchronously.
It works just like nmdb_set(), except it returns only after the database confirms it has stored the value.
db | connection instance. | |
key | the key. | |
ksize | the key size. | |
val | the value | |
vsize | size of the value. |
int nmdb_del | ( | nmdb_t * | db, | |
const unsigned char * | key, | |||
size_t | ksize | |||
) |
Delete a key.
It returns after the command has been acknowledged by the server, but does not wait for the database to confirm it. In any case, further GET requests will return the key is missing, even if this delete has not reached the backend yet.
db | connection instance. | |
key | the key. | |
ksize | the key size. |
int nmdb_del_sync | ( | nmdb_t * | db, | |
const unsigned char * | key, | |||
size_t | ksize | |||
) |
Delete a key synchronously.
It works just like nmdb_del(), except it returns only after the database confirms it has deleted the key.
db | connection instance. | |
key | the key. | |
ksize | the key size. |
int nmdb_cas | ( | nmdb_t * | db, | |
const unsigned char * | key, | |||
size_t | ksize, | |||
const unsigned char * | oldval, | |||
size_t | ovsize, | |||
const unsigned char * | newval, | |||
size_t | nvsize | |||
) |
Perform an atomic compare-and-swap.
This command will set the value associated to a key to newval, provided it currently is oldval, in an atomic way. Equivalent to atomically doing:
if get(key) == oldval, then set(key, newval)
db | connection instance. | |
key | the key. | |
ksize | the key size. | |
oldval | the old, expected value. | |
ovsize | size of the expected value. | |
newval | the new value to set. | |
nvsize | size of the new value. |
int nmdb_incr | ( | nmdb_t * | db, | |
const unsigned char * | key, | |||
size_t | ksize, | |||
int64_t | increment, | |||
int64_t * | newval | |||
) |
Atomically increment the value associated with a key.
This command atomically increments the value associated with a key in the given increment. However, there are requirements on the current value: it must be a NULL-terminated string with only a number in base 10 in it (i.e. it must be parseable by strtoll(3)).
db | connection instance. | |
key | the key. | |
ksize | the key size. | |
increment | the value to add to the current one (can be negative). | |
[out] | newval | pointer to an integer that will be set to the new value. |