ssdb替代mysql_SSDB Redis替代品

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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值