两个ssdb lua sdk 推荐

lua 作为嵌入脚本使用很方便,这里推荐两个ssdb lua 客户端。

https://github.com/LazyZhu/lua-resty-ssdb 10 我一直用这个

https://github.com/eleme/lua-resty-ssdb 5

前者使用示例

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)
ngx.say("dog: ", res[1])

Relative Articles