lua 作为嵌入脚本使用很方便,这里推荐两个ssdb lua 客户端。
https://github.com/LazyZhu/lua-resty-ssdb 我一直用这个
https://github.com/eleme/lua-resty-ssdb
前者使用示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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])
本文网址: https://pylist.com/topic/115.html 转摘请注明来源