local redis = require("redis")
local cache = redis.new()
local ok, err = cache.connect(cache, '127.0.0.1', '6000')
if not ok then
ngx.say("failed to connect redis:", err)
return
end
cache:set_timeout(3000)
res, err = cache:set("key1", "nginx test lua")
if not ok then
ngx.say("failed to set key1: ", err)
return
end
ngx.say("set result: ", res)
local res, err = cache:get("key1")
if not res then
ngx.say("failed to get key1: ", err)
return
end
if res == ngx.null then
ngx.say("key1 not found.")
return
end
ngx.say("key1: ", res)
local ok, err = cache:close()
if not ok then
ngx.say("failed to close redis:", err)
return
end