热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

SSDBRedis替代品

SSDB是一个快速的用来存储十亿级别列表数据的开源NoSQL数据库。项目地址:github.comideawussdbssdb.io特性替代Redis数据库,Redis的100倍容量LevelDB网络支持,使用CC++开发RedisAPI兼容,支持Redis客户端适合存储集

SSDB是一个快速的用来存储十亿级别列表数据的开源 NoSQL 数据库。项目地址:https://github.com/ideawu/ssdbhttp://ssdb.io/ 特性 替代 Redis 数据库, Redis 的 100 倍容量 LevelDB 网络支持, 使用 C/C++ 开发 Redis API 兼容, 支持 Redis 客户端 适合存储集

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) 来获取。 ssdb-1

架构

ssdb-2

安装

下载压缩包,解压缩
wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zip
unzip master
cd ssdb-master
编译
make
安装(可选)
sudo make install
运行
./ssdb-server ssdb.conf
或者以后台的方式运行
./ssdb-server -d ssdb.conf
ssdb命令行
./tools/ssdb-cli -p 8888
停止ssdb-server
kill `cat ./var/ssdb.pid`

使用

PHP

getMessage());
}
$ret = $ssdb->set('key', 'value');
if($ret === false){
    // error!
}
echo $ssdb->get('key');

Python

使用pyssdb
>>> import pyssdb
>>> c = pyssdb.Client()
>>> c.set('key', 'value')
1
>>> c.get('key')
'value'
>>> c.hset('hash', 'item', 'value')
1
>>> c.hget('hash', 'item')
'value'
>>> c.hget('hash', 'not exist') is None
True
>>> c.incr('counter')
1
>>> c.incr('counter')
2
>>> c.incr('counter')
3
>>> c.keys('a', 'z', 1)
['counter']
>>> c.keys('a', 'z', 10)
['counter', 'key']

Ruby

使用ssdb-rb
require "ssdb"
ssdb = SSDB.new url: "ssdb://1.2.3.4:8889"
ssdb.set("mykey", "hello world")
# => true
ssdb.get("mykey")
# => "hello world"
ssdb.batch do
  ssdb.set "foo", "5"
  ssdb.get "foo"
  ssdb.incr "foo"
end
# => [true, "5", 6]

Go

package main
import (
        "fmt"
        "os"
        "./ssdb"
       )
func main(){
    ip := "127.0.0.1";
    port := 8888;
    db, err := ssdb.Connect(ip, port);
    if(err != nil){
        os.Exit(1);
    }
    var val interface{};
    db.Set("a", "xxx");
    val, err = db.Get("a");
    fmt.Printf("%s\n", val);
    db.Del("a");
    val, err = db.Get("a");
    fmt.Printf("%s\n", val);
    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);
    if err != nil{
        os.Exit(1);
    }
    if len(resp) % 2 != 1{
        fmt.Printf("bad response");
        os.Exit(1);
    }
    fmt.Printf("Status: %s\n", resp[0]);
    for i:=1; i

ngx_lua

使用lua-resty-ssdb
lua_package_path "/path/to/lua-resty-ssdb/lib/?.lua;;";
server {
    location /test {
        content_by_lua '
            local ssdb = require "resty.ssdb"
            local db = ssdb:new()
            db:set_timeout(1000) -- 1 sec
            local ok, err = db:connect("127.0.0.1", 8888)
            if not ok then
                ngx.say("failed to connect: ", err)
                return
            end
            ok, err = db:set("dog", "an animal")
            if not ok then
                ngx.say("failed to set dog: ", err)
                return
            end
            ngx.say("set result: ", ok)
            local res, err = db:get("dog")
            if not res then
                ngx.say("failed to get dog: ", err)
                return
            end
            if res == ngx.null then
                ngx.say("dog not found.")
                return
            end
            ngx.say("dog: ", res)
            db:init_pipeline()
            db:set("cat", "Marry")
            db:set("horse", "Bob")
            db:get("cat")
            db:get("horse")
            local results, err = db:commit_pipeline()
            if not results then
                ngx.say("failed to commit the pipelined requests: ", err)
                return
            end
            for i, res in ipairs(results) do
                if type(res) == "table" then
                    if not res[1] then
                        ngx.say("failed to run command ", i, ": ", res[2])
                    else
                        -- process the table value
                    end
                else
                    -- process the scalar value
                end
            end
            -- put it into the connection pool of size 100,
            -- with 0 idle timeout
            local ok, err = db:set_keepalive(0, 100)
            if not ok then
                ngx.say("failed to set keepalive: ", err)
                return
            end
            -- or just close the connection right away:
            -- local ok, err = db:close()
            -- if not ok then
            --     ngx.say("failed to close: ", err)
            --     return
            -- end
        ';
    }
}

C++

#include 
#include 
#include 
#include 
#include "SSDB.h"
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);
    if(client == NULL){
        printf("fail to connect to server!\n");
        return 0;
    }
    ssdb::Status s;
    s = client->set("k", "hello ssdb!");
    if(s.ok()){
        printf("k = hello ssdb!\n");
    }else{
        printf("error!\n");
    }
    delete client;
    return 0;
}
推荐阅读
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 本文介绍了在Win10上安装WinPythonHadoop的详细步骤,包括安装Python环境、安装JDK8、安装pyspark、安装Hadoop和Spark、设置环境变量、下载winutils.exe等。同时提醒注意Hadoop版本与pyspark版本的一致性,并建议重启电脑以确保安装成功。 ... [详细]
  • 本文整理了Java中java.lang.NoSuchMethodError.getMessage()方法的一些代码示例,展示了NoSuchMethodErr ... [详细]
  • 开发笔记:Python之路第一篇:初识Python
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了Python之路第一篇:初识Python相关的知识,希望对你有一定的参考价值。Python简介& ... [详细]
  • Allegro总结:1.防焊层(SolderMask):又称绿油层,PCB非布线层,用于制成丝网印板,将不需要焊接的地方涂上防焊剂.在防焊层上预留的焊盘大小要比实际的焊盘大一些,其差值一般 ... [详细]
  • 有意向可以发简历到邮箱内推.简历直达组内Leader.能做同事的话,内推奖励全给你. ... [详细]
  • 安装goget-ugithub.comgomoduleedigoedis连接var(redisHost127.0.0.1:6379redisPassroot)创建redis ... [详细]
  • ☞░前往老猿Python博客https:blog.csdn.netLaoYuanPython░一、引言在写该文之前,老猿就图像的一些运算已经单独边学边发了࿰ ... [详细]
  • rust编程这篇文章是关于我通过解决Twitch上尚未解决的所有CtCI问题来学习Rust的经验。英国科学博物馆集团AdaLovelace的肖像Rust徽标,由Moz ... [详细]
  • ruby 输出彩色内容到控制台
    程序输出控制台时,为了区分输出信息的严重程度,可以使用颜色、符号等来做标识。ruby也支持设置输出内容的颜色,比如运行以下代码:以下内容是百度到的,因发现很多博客都是同样的写法,所 ... [详细]
  • 作为老牌的Web后端编程语言,PHP在全球市场占有率非常高。PHP是全球五大热门的编程语言,是唯一入选的脚本语言;从各个招聘网站的数据上来 ... [详细]
  • 本文介绍了Python版Protobuf的安装和使用方法,包括版本选择、编译配置、示例代码等内容。通过学习本教程,您将了解如何在Python中使用Protobuf进行数据序列化和反序列化操作,以及相关的注意事项和技巧。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 1、概述首先和大家一起回顾一下Java消息服务,在我之前的博客《Java消息队列-JMS概述》中,我为大家分析了:然后在另一篇博客《Java消息队列-ActiveMq实战》中 ... [详细]
author-avatar
金瑞期货秦臻
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有