-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Per @ankopainting suggestions in #1:
The second thing i just wanted to comment on (sorry for the nitpick), is the mutex is unnecessary. Instead you could use a redis transaction. Here is what I'm doing;
ret = redis.pipelined do
redis.zremrangebyscore full_key, 0, clear_before_timestamp # remove requests past period
redis.zcard full_key # count of how many requests we've received
redis.zadd full_key, current_timestamp, SecureRandom.uuid
redis.expire full_key, period
end
The redis docs say;
All the commands in a transaction are serialized and executed sequentially. It can never happen that a request issued by another client is served in the middle of the execution of a Redis transaction. This guarantees that the commands are executed as a single isolated operation.
https://redis.io/topics/transactions
Need to investigate how viable this option is and if mutex can be replaced with a transaction it could clean up code a bit.
Metadata
Metadata
Assignees
Labels
No labels