local redis = require "resty.redis"


local function close_redis(red)
    if not red then
        return
    end

    local pool_max_idle_time = 60000
    local pool_size = 10
    local ok, err = red:set_keepalive(pool_max_idle_time, pool_size)
    if not ok then
        ngx_log(ngx_err, "set redis keepalive error: ", err)
    end
end


local red = redis:new()
red:set_timeout(1000)
local ok, err = red:connect(redis_host, redis_port)
if not ok then
    ngx_log(ngx_err, "connect to redis server error: ", err)
    return
end

local count, err = red:get_reused_times()
if count == 0 then
    local ok, err = red:auth(redis_pass)
    if not ok then
        ngx_log(ngx_err, "redis password error: ", err)
        return
    end
elseif err then
    ngx_log(ngx_err, "get redis reused_times error: ", err)
    return
else
    ngx_log(ngx_info, "get_reused_times: ", count)
end

red:mget()
red:mget(unpack({key1, key2}))
red:set()
red:del()
red:smembers()

close_redis(red)

标签: nginx

添加新评论