distributed-redis-tool icon indicating copy to clipboard operation
distributed-redis-tool copied to clipboard

为什么每次incr都要调用 expire

Open tianleios opened this issue 6 years ago • 1 comments

else -- 没有达到阈值 value + 1 redis.call("INCRBY", key, 1) redis.call("EXPIRE", key, 2) return curentLimit + 1 end

tianleios avatar Jan 04 '19 06:01 tianleios

脚本有问题,应该这么写 local key = KEYS[1] -- 限流大小 local limit = tonumber(ARGV[1])

-- 获取当前流量大小 local curentLimit = tonumber(redis.call('get', key) or "0")

if curentLimit + 1 > limit then -- 达到限流大小 返回 return 0; else -- 没有达到阈值 value + 1 redis.call("INCRBY", key, 1) if curentLimit == 0 then redis.call("EXPIRE", key, 1) return curentLimit + 1 end

majintao avatar Feb 14 '19 07:02 majintao