本文地址: http://www.ttlsa.com/redis/ssdb-redis-alternatives/
除非注明,博客文章均为"运维生存时间"原创,转载请标明本文地址
SSDB是一个快速的用来存储十亿级别列表数据的开源 NoSQL 数据库。
项目地址:https://github.com/ideawu/ssdb
http://ssdb.io/
特性
- 替代 Redis 数据库, Redis 的 100 倍容量
- LevelDB 网络支持, 使用 C/C++ 开发
- Redis API 兼容, 支持 Redis 客户端
- 适合存储集合数据, 如 list, hash, zset…
- 客户端 API 支持的语言包括: C++、PHP、Python、Cpy、Java、NodeJS、Ruby、Go。
- 持久化的队列服务
- 主从复制, 负载均衡
性能
1000请求:
writeseq : 0.546 ms/op 178.7 MB/s |
writerand : 0.519 ms/op 188.1 MB/s |
readseq : 0.304 ms/op 321.6 MB/s |
readrand : 0.310 ms/op 315.0 MB/s |
并发:
========== set ========== |
qps: 44251 , time: 0.226 s |
========== get ========== |
qps: 55541 , time: 0.180 s |
========== del ========== |
qps: 46080 , time: 0.217 s |
========== hset ========== |
qps: 42338 , time: 0.236 s |
========== hget ========== |
qps: 55601 , time: 0.180 s |
========== hdel ========== |
qps: 46529 , time: 0.215 s |
========== zset ========== |
qps: 37381 , time: 0.268 s |
========== zget ========== |
qps: 41455 , time: 0.241 s |
========== zdel ========== |
qps: 38792 , time: 0.258 s |
在MacBook Pro 13 (Retina屏幕)上运行。
与redis的比较:
性能数据使用 ssdb-bench(SSDB) 和 redis-benchmark(Redis) 来获取。
架构
安装
下载压缩包,解压缩
wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zip |
编译
安装(可选)
运行
或者以后台的方式运行
./ssdb-server -d ssdb.conf |
ssdb命令行
停止ssdb-server
kill ` cat ./var/ssdb.pid` |
使用
PHP
include_once( 'SSDB.php' ); |
$ssdb = new SimpleSSDB( '127.0.0.1' , 8888); |
die(__LINE__ . ' ' . $e->getMessage()); |
$ret = $ssdb-> set ( 'key' , 'value' ); |
Python
使用pyssdb
>>> c. set ( 'key' , 'value' ) |
>>> c.hset( 'hash' , 'item' , 'value' ) |
>>> c.hget( 'hash' , 'item' ) |
>>> c.hget( 'hash' , 'not exist' ) is None |
Ruby
使用ssdb-rb
ssdb = SSDB . new url: "ssdb://1.2.3.4:8889" |
ssdb.set( "mykey" , "hello world" ) |
Go
db, err := ssdb.Connect(ip, port); |
db.Do( "zset" , "z" , "a" , 3); |
db.Do( "multi_zset" , "z" , "b" , -2, "c" , 5, "d" , 3); |
resp, err := db.Do( "zrange" , "z" , 0, 10); |
fmt.Printf( "bad response" ); |
fmt.Printf( "Status: %s\n" , resp[0]); |
for i:=1; i<len(resp); i+=2{ |
fmt.Printf( " %s : %3s\n" , resp[i], resp[i+1]); |
使用lua-resty-ssdb
lua_package_path "/path/to/lua-resty-ssdb/lib/?.lua;;" ; |
local ssdb = require "resty.ssdb" |
db:set_timeout(1000) -- 1 sec |
local ok, err = db:connect( "127.0.0.1" , 8888) |
ngx.say( "failed to connect: " , err) |
ok, err = db:set( "dog" , "an animal" ) |
ngx.say( "failed to set dog: " , err) |
ngx.say( "set result: " , ok) |
local res, err = db:get( "dog" ) |
ngx.say( "failed to get dog: " , err) |
ngx.say( "dog not found." ) |
local results, err = db:commit_pipeline() |
ngx.say( "failed to commit the pipelined requests: " , err) |
for i, res in ipairs(results) do |
if type(res) == "table" then |
ngx.say( "failed to run command " , i, ": " , res[2]) |
-- process the table value |
-- process the scalar value |
-- put it into the connection pool of size 100, |
local ok, err = db:set_keepalive(0, 100) |
ngx.say( "failed to set keepalive: " , err) |
-- or just close the connection right away: |
-- local ok, err = db:close() |
-- ngx.say( "failed to close: " , err) |
C++
int main( int argc, char **argv){ |
const char *ip = (argc >= 2)? argv[1] : "127.0.0.1" ; |
int port = (argc >= 3)? atoi (argv[2]) : 8888; |
ssdb::Client *client = ssdb::Client::connect(ip, port); |
printf ( "fail to connect to server!\n" ); |
s = client->set( "k" , "hello ssdb!" ); |
printf ( "k = hello ssdb!\n" ); |
<iframe id="aswift_0" style="left: 0px; position: absolute; top: 0px;" name="aswift_0" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="728" height="90"></iframe>