All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jie.opensource.distributed-redis-tool.1.0.2.source-code.limit.lua Maven / Gradle / Ivy

--
-- Created by IntelliJ IDEA.
-- User: crossoverJie
-- Date: 22/04/2018
-- Time: 15:36
-- To change this template use File | Settings | File Templates.
--
--lua 下标从 1 开始
-- 限流 key
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)
    redis.call("EXPIRE", key, 2)
    return curentLimit + 1
end





© 2015 - 2024 Weber Informatics LLC | Privacy Policy