REDIS的嵌入式实现。 http://vedis.symisc.net
Vedis是一个可嵌入的数据存储C库,其构建的70多个命令与REDIS相似,但没有网络层,因为Vedis在主机应用程序的相同过程中运行。
与大多数其他数据存储(即Memcache,redis)不同,Vedis没有单独的服务器进程。 Vedis读取并直接写入普通磁盘文件。单个磁盘文件中包含一个包含多个集合的完整数据库。数据库文件格式是跨平台,您可以在32位和64位系统之间或在大型和小型架构之间自由复制数据库。
Vedis是一个无依赖性的独立C库。它需要外部库或操作系统的极少支持。这使其非常适合用于缺乏台式计算机支持基础架构的嵌入式设备。这也使Vedis适合在需要运行的应用程序中使用而无需修改各种配置计算机的应用程序。
数据存储引擎的主要任务是尽可能快地存储和检索记录。 Vedis支持结构化和原始数据存储。
结构化数据存储通过命令执行接口(CEI)提交给客户端。基本上,您通过Vedis_exec()执行一个或多个命令Ala redis(IE设置键值;获取键,HSET ...),然后通过VEDIS_EXEC_RESULT()提取执行结果(命令的返回值)。有关内置命令列表,请参阅以下页面。
通过密钥/值存储界面向客户端提供了原始数据存储。 VEDIS是类似于伯克利DB,东京橱柜,LevelDB等的标准密钥/价值存储,但具有丰富的功能集,包括对交易(酸),并发读取器等的支持。
在KV商店下,键和值都被视为简单的字节数组,因此内容可以是ASCII字符串,二进制BLOB甚至磁盘文件中的任何内容。 KV存储层通过一组接口显示给客户端,其中包括:Vedis_kv_store(),Vedis_kv_append(),Vedis_kv_fetch_callback(),Vedis_kv_append_fmt(),vedis_kv_fetch_callback()
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 ==> %s n " ,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 ==> %s n " ,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 %s n " ,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 ==> %d n " ,pid); /* Should be 1024 */
}
/* Finally, auto-commit the transaction and close our datastore */
vedis_close (pStore);访问http://vedis.symisc.net