drogon icon indicating copy to clipboard operation
drogon copied to clipboard

Support redis clusters

Open omar-mohamed-khallaf opened this issue 3 years ago • 4 comments
trafficstars

Is your feature request related to a problem? Please describe. The current implementation only support standalone redis servers, but for redis clusters where the hash slots are distributed across more than one server I get an exception with the following text: MOVED 9695 10.42.1.81:6379

Describe the solution you'd like I would like the client to handle redis clusters. As far as I understand from other libraries that support it is this can be implemented as:

  1. CLUSTER NODES to get info about the nodes (if it returns an error then it's a standalone server)
  2. apply crc16 to keys in commands sent to the server or text between {} in keys (hash tags)
  3. send the command to the right server to bypass the exception (and better for performance)

This also requires handling of:

  • A connection pool to all servers in the cluster.
  • Updating the connection pool server addresses in case a node changes it address
  • Re-resolving the server host name in case all nodes changed their addresses at the same time (in case of a failure)

Describe alternatives you've considered Using redis-plus-plus seems good for now, but handling this in the framework will be much better.

omar-mohamed-khallaf avatar Apr 28 '22 08:04 omar-mohamed-khallaf

I also encountered such demand a while ago. What about using a proxy such as redis-cluster-proxy (a redis official project)? Supporting cluster in drogon is basically re-develop a library such as redis-cluster (formerly redis-vip).

hwc0919 avatar Apr 30 '22 10:04 hwc0919

Both looks very nice. I'm keeping the issue open as I think I will try to replace hiredis with hiredis-cluster. Should I not ?

omar-mohamed-khallaf avatar Apr 30 '22 11:04 omar-mohamed-khallaf

I'm not sure... That will be a huge change. And we don't know about the quality of that project. It doesn't seem to be widely used.

What do you think? @an-tao @marty1885

hwc0919 avatar Apr 30 '22 15:04 hwc0919

redis-cluster-proxy still has some work to be done project status . As far as I understand redis-cluster looks like a wrapper around hiredis maintaining some data structures to manage the cluster. Although the project doesn't seem nicely structured like drogon but it's C.

I think that the changes needed to keep the existing functionality of drogon aren't big, most of the changes are from redis*() to redisCluster*() but I was thinking about handling name resolving more properly as current implementation resolves the name once during the reading of the config file.

This is going to require changes in the client implementation so the client can know about the hostname and use it when the connection is disconnected or when establishing a new connections fails (some ideas I thought of).

To be honest I think this will take me some time, but I would like to know your decision and in the meantime I will try to organize my thoughts, understand the existing code and prepare for my exams 🥲.

omar-mohamed-khallaf avatar Apr 30 '22 20:04 omar-mohamed-khallaf