ExHammer / hammer-backend-redis

A Redis backend for for the Hammer rate-limiter
https://hexdocs.pm/ExHammer/hammer-backend-redis
MIT License
48 stars 32 forks source link

Redis cluster support for do_count_hit #40

Open carlogilmar opened 1 year ago

carlogilmar commented 1 year ago

Hi! As I mention here: https://github.com/ExHammer/hammer-backend-redis/issues/39 we had problems using this with a Redis Cluster. Looking the documentation looks like the client connector needs to enable a cluster mode to make operations without the MOVED error.

Replication

  1. I created a redis cluster: https://redis.io/docs/management/scaling/#create-and-use-a-redis-cluster
  2. I connected to just one node in the config file.

Possible Solution

image

First Approach to design the solution

  1. Validate the MOVED error in the do_count_hit/5 function.
  2. Parse the correct node direction from the redix error.
  3. Create a new connection to that node.
  4. This will happen any time when you are in a cluster, we need to validate the connections to avoid create many connections to the same node. I achieve this registering the node direction as name.

Feedback

I'd like to get feedback on this possible solution, other pending part is add tests for this, but I'm a little bit confusing on that part. What do you think? Maybe there are other solutions.

epinault commented 7 months ago

looks like this need to rebased if you get get a chance