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