NoSQL 數據服務器:Reveldb
reveldb 一個基于 google leveldb 的 NoSQL 數據服務器,網絡連接采用了 libevent 的 HTTP 接口,因此 reveldb 天生就適合處理 HTTP 請求。但更確切地說,reveldb 并沒有直接采用 libevent 的 HTTP 接口,而是使用了另外一個基于 libevent 的網絡連接庫 libevhtp(https://github.com/ellzey/libevhtp),并對它做了適當的修改,使之成為 reveldb 的底層組件 evhttpx(https://github.com/forhappy/reveldb/tree/master/src/evhttpx), evhttpx 為 reveldb 提供了 HTTP 和 HTTPS 支持,因此,reveldb 除了能夠處理 HTTP 請求外,也能夠處理 HTTPS 請求,這一特性是 Kyoto Tycoon 沒有的。
Reveldb 定位于 Kyoto Tycoon 類似,也是一個數據庫網絡層的服務,具體一點就是 Leveldb 的網絡層接口(因為 leveldb 本身只是一個程序庫,并沒有服務器/客戶端的概念),reveldb 封裝了 leveldb 的絕大部分操作,如 Snapshot, Writebatch, Iterator 等等,并且在此基礎之上擴展了很多命令,比如 string 的 append, prepend, insert,Key-Value 的 mset, mget, mdel, seize, mseize,此外還有 range query, 基于編輯距離的查找,正則式 regex 匹配查找;同時還提供了一些數據庫管理的命令,如compact, repair, destroy 等;Ling外,reveldb 支持打開多個數據庫,底層使用了紅黑樹緩存各個客戶端已經打開的 leveldb 實例。
HTTP RPC 示例:
/rpc/echo
-
Description: Echo back the input data as the output data, as well as HTTP headers, just for testing.
-
input: (optional): arbitrary records.
-
output: (optional): corresponding records to the input data.
-
status code: 200.
-
sample request:
http://127.0.0.1:8088/rpc/echo?db=default&key=hello&value=world
-
sample response:
{ "code": 200, "status": "OK", "message": "Reveldb echoed the HTTP headers and query arguments of your request.", "date": "Mon, 17 Dec 2012 12:50:22 GMT", "request": { "headers": { "Host": "127.0.0.1:8088", "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:17.0) Gecko/20100101 Firefox/17.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive" }, "arguments": { "db": "default", "key": "hello", "value": "world" } } }
/rpc/set
-
Description:
-
input: db: the database identifier.
-
input: key: key to be added.
-
input: value: value along with the key to be added.
-
status code: 200.
-
sample request:
http://127.0.0.1:8088/rpc/set?db=hello&key=hello&value=world
-
sample response:
{ "code": 200, "status": "OK", "message": "Set key-value pair done.", "date": "Thu, 27 Dec 2012 09:11:26 GMT" }
/rpc/get
-
Description:
-
input: db: the database identifier.
-
input: key: which key to get.
-
status code: 200.
-
sample request:
http://127.0.0.1:8088/rpc/get&db=hello&key=hello
-
sample response:
{ "code": 200, "status": "OK", "message": "Get key-value pair done.", "date": "Thu, 27 Dec 2012 09:19:05 GMT", "kv": { "hello": "worldworld" } }