local function redis_get()
local config = require 'core.config'
local redis = require 'resty.redis'
local r = redis:new()
r:add_commands('srandmembers') -- srem key member1 ...,spop key [conut], srandmember key [count]
local csrv_rd_tmo = 1000
r:set_timeout(csrv_rd_tmo)
local ok, err = r:connect_cluster(config.kvhosts, config.kvhost_pwd)
if not ok then
ngx.log(ngx.ERR, 'redis_get:', err)
r:close()
return false
end
local csrv_db_idx = 5
local rv, err = r:select(csrv_db_idx)
if not rv then
r:close()
return false
end
local k = 'xxkey'
local value, err = r:srandmember(k, 100)
if not value then
r:close()
return false
end
if type(value) == 'table' and #value > 0 then
local ok, err = r:srem(k, unpack(value))
if not ok then
r:close()
return false
end
return value
end
return false
end
ngx.timer.at(5, redis_get)
会发现redis.new 的占用空间在500字节左右,会每5s创建一次redis.new 对象,导致内存线性增长。