An Embedded Implementation of Redis. http://vedis.symisc.net
Vedis is an embeddable datastore C library built with over 70 commands similar in concept to Redis but without the networking layer since Vedis run in the same process of the host application.
Unlike most other datastores (i.e. memcache, Redis), Vedis does not have a separate server process. Vedis reads and writes directly to ordinary disk files. A complete database with multiple collections, is contained in a single disk file. The database file format is cross-platform, you can freely copy a database between 32-bit and 64-bit systems or between big-endian and little-endian architectures.
Vedis is a self-contained C library without dependency. It requires very minimal support from external libraries or from the operating system. This makes it well suited for use in embedded devices that lack the support infrastructure of a desktop computer. This also makes Vedis appropriate for use within applications that need to run without modification on a wide variety of computers of varying configurations.
The principal task of a datastore engine is to store and retrieve records as fast as possible. Vedis support both structured and raw data storage.
Structured data storage is presented to clients via the command execution interface (CEI). Basically, you execute one or more commands ala Redis (i.e. SET key value; GET key, HSET...) via vedis_exec() and you extract the execution result (The return value of the command) via vedis_exec_result(). Refer to the following page for the list of built-in commands.
Raw data storage is presented to clients via the Key/Value store interfaces. Vedis is a standard key/value store similar to Berkeley DB, Tokyo Cabinet, LevelDB, etc. but with a rich feature set including support for transactions (ACID), concurrent reader, etc.
Under the KV store, both keys and values are treated as simple arrays of bytes, so content can be anything from ASCII strings, binary blob and even disk files. The KV store layer is presented to clients via a set of interfaces, these includes: vedis_kv_store(), vedis_kv_append(), vedis_kv_fetch_callback(), vedis_kv_append_fmt(), etc.
vedis *pStore; /* Datastore handle */
int rc;
/* Create our datastore */
rc = vedis_open(&pStore,argc > 1 ? argv[1] /* On-disk DB */ : ":mem:"/* In-mem DB */);
if( rc != VEDIS_OK ){ /* Seriously? */ return; }
/* Execute the simplest command */
rc = vedis_exec(pStore,"SET test 'Hello World'",-1);
if( rc != VEDIS_OK ){ /* Handle error */ }
/* Another simple command (Multiple set) */
rc = vedis_exec(pStore,"MSET username james age 27 mail [email protected]",-1);
if( rc != VEDIS_OK ){ /* Handle error */ }
/* A quite complex command (Multiple hash set) using foreign data */
rc = vedis_exec_fmt(pStore,
"HMSET config pid %d user %s os %s scm %s",
1024 /* pid */,
"dean", /* user */
"FreeBSD", /* OS */
"Git" /* SCM */
);
if( rc != VEDIS_OK ){ /* Handle error */ }
/* Fetch some data */
rc = vedis_exec(pStore,"GET test",-1);
if( rc != VEDIS_OK ){ /* Seriously? */ }
/* Extract the return value of the last executed command (i.e. 'GET test') " */
vedis_exec_result(pStore,&pResult);
{
const char *zResponse;
/* Cast the vedis object to a string */
zResponse = vedis_value_to_string(pResult,0);
/* Output */
printf(" test ==> %sn",zResponse); /* test ==> 'Hello world' */
}
vedis_exec(pStore,"GET mail",-1);
/* 'GET mail' return value */
vedis_exec_result(pStore,&pResult);
{
const char *zResponse;
/* Cast the vedis object to a string */
zResponse = vedis_value_to_string(pResult,0);
/* Output */
printf(" mail ==> %sn",zResponse); /* Should be '[email protected]' */
}
/*
* A command which return multiple value in array.
*/
vedis_exec(pStore,"MGET username age",-1); /* james 27*/
vedis_exec_result(pStore,&pResult);
if( vedis_value_is_array(pResult) ){
/* Iterate over the elements of the returned array */
vedis_value *pEntry;
puts("Array entries:");
while((pEntry = vedis_array_next_elem(pResult)) != 0 ){
const char *zEntry;
/* Cast to string and output */
zEntry = vedis_value_to_string(pEntry,0);
/* Output */
printf("t%sn",zEntry);
}
}
/* Extract hashtable data */
vedis_exec(pStore,"HGET config pid",-1); /* 1024 */
vedis_exec_result(pStore,&pResult);
{
int pid;
/* Cast to integer */
pid = vedis_value_to_int(pResult);
/* Output */
printf("pid ==> %dn",pid); /* Should be 1024 */
}
/* Finally, auto-commit the transaction and close our datastore */
vedis_close(pStore);visit http://vedis.symisc.net