local function close_redis(red)
if not red then
return
end
local pool_max_idle_time = 10000
local pool_size = 100
local ok,err = red:set_keepalive(pool_max_idle_time,pool_size)
if not ok then
ngx.say("set keepalive error:" ,err)
end
end
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000)
local ok,err = red:connect("47.96.64.100",6379)
if not ok then
ngx.say("connect to redis error: ",err)
return close_redis(red)
end
local count,err = red:get_reused_times()
if 0 == count then
ok,err = red:auth("123456")
if not ok then
ngx.say("auth fail")
return
end
elseif err then
ngx.say("failed to get reused times: ",err)
return
end
ngx.say(red:get("dog"))
close_redis(red)