-- 令牌桶退款脚本 -- KEYS[1]: 限流器唯一标识 -- ARGV[1]: 退还的令牌数 -- ARGV[2]: 桶容量(上限) local key = KEYS[1] local refund = tonumber(ARGV[1]) local capacity = tonumber(ARGV[2]) local bucket = redis.call('HMGET', key, 'tokens', 'last_time') local tokens = tonumber(bucket[1]) if not tokens then return 0 end tokens = math.min(capacity, tokens + refund) redis.call('HSET', key, 'tokens', tokens) return 1