Skip to content

Commit

Permalink
throttle: switch to older ZRANGEBYSCORE
Browse files Browse the repository at this point in the history
We were using the newer ZRANGE BYSCORE syntax, but most of the
supported distros are running older versions of redis that may
have bugs or don't fully support this syntax, so let's use
the older version of this functionality for now.
  • Loading branch information
wez committed Jan 6, 2025
1 parent e39acfe commit 52fce3c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/throttle/src/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ redis.log(redis.LOG_DEBUG, "limiter: ZCARD", KEYS[1], " -> count=", count)
if count + 1 > limit then
-- find the next expiration time
redis.log(redis.LOG_DEBUG, "limiter: going to call ZRANGE", KEYS[1])
local smallest = redis.call("ZRANGE", KEYS[1], "-inf", "+inf", "BYSCORE", "LIMIT", 0, 1, "WITHSCORES")
redis.log(redis.LOG_DEBUG, "limiter: going to call ZRANGEBYSCORE", KEYS[1])
local smallest = redis.call("ZRANGEBYSCORE", KEYS[1], "-inf", "+inf", "WITHSCORES", "LIMIT", 0, 1)
redis.log(redis.LOG_DEBUG, "limiter: ZRANGE", KEYS[1], " -> smallest size=", #smallest, "uuid=", smallest[1], "exp=", smallest[2])
redis.log(redis.LOG_DEBUG, "limiter: ZRANGEBYSCORE", KEYS[1], " -> smallest size=", #smallest, "uuid=", smallest[1], "exp=", smallest[2])
redis.log(redis.LOG_DEBUG, "limiter: ZRANGEBYSCORE", KEYS[1], " -> uuid=", smallest[1], "exp=", smallest[2])
-- smallest holds the uuid and its expiration time;
-- we want to just return the remaining time interval
Expand Down

0 comments on commit 52fce3c

Please sign in to comment.