Skip to content

Investigate replacing mutex with a redis transaction #2

@ryakh

Description

@ryakh

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions