Database API

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.

Detailed Description

Functions that affect the database and the cache.


Function Documentation

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.

Parameters:
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.
Returns:
the size of the value written to the given buffer, -1 if the key is not in the database, or -2 if there was an error.
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.

Parameters:
db connection instance.
key the key.
ksize the key size.
val the value
vsize size of the value.
Returns:
1 on success, < 0 on error.
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.

Parameters:
db connection instance.
key the key.
ksize the key size.
val the value
vsize size of the value.
Returns:
1 on success, < 0 on error.
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.

Parameters:
db connection instance.
key the key.
ksize the key size.
Returns:
1 on success, < 0 on error.
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.

Parameters:
db connection instance.
key the key.
ksize the key size.
Returns:
1 on success, < 0 on error.
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)

Parameters:
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.
Returns:
2 on success, 1 if the current value does not match oldval, 0 if the key is not in the database, or < 0 on error.
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)).

Parameters:
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.
Returns:
2 if the increment was successful, 1 if the current value was not in an appropriate format, 0 if the key is not in the database, or < 0 on error.
Generated on Sun Oct 10 19:50:36 2010 for libnmdb (public) by  doxygen 1.6.3