amakawa / redic

Lightweight Redis Client
MIT License
120 stars 14 forks source link

Connect to multiple redis server with failover #8

Closed phuongnd08 closed 4 years ago

phuongnd08 commented 9 years ago

How would I setup redic if I want to use multiple redis servers with the possibility of failover (the one that being connected by the client went down)

soveran commented 9 years ago

I'm working on that right now, I may be able to release something very soon. It won't be a modification on Redic, but a different library that uses Redic.

phuongnd08 commented 9 years ago

Awesome. I hope that library you were to mention is Ohm because it's what I'm in need right now :smile:

phuongnd08 commented 9 years ago

@soveran I'm working on this: https://github.com/phuongnd08/redic-sentinel Could you give some reviews?

soveran commented 9 years ago

Excellent! I just checked it and I have some questions. You modify the Redic constant and also Redic::Client, is that needed to make it work with Ohm?

In general, it is better to use a different constant (for example, RedicSentinel), and design it so that internally it uses Redic. The reason for that is because by modifying Redic itself, you may get conflicts if a library wants to use Redic in some other way without the sentinel modifications. Ohm allows you to use any client that uses the same API as Redic, that is, once initialized it should reply to call, queue and commit.

I will review the rest later, but for now we can start thinking about that.

soveran commented 9 years ago

Forgot to mention how to use a different client with Ohm, it goes like this:

Ohm.redis = MyClient.new(...)

As long as the instance of MyClient responds to call, queue and commit, everything will work.

phuongnd08 commented 9 years ago

Cool. I'm just not sure how could commit be implemented on top of thing like redis-rb. If we can simplify our project to just redis-rb rather than redic then I can focus on contribute work to redis-sentinel rather than fork to the new redic-sentinel

phuongnd08 commented 9 years ago

Per your questions, I need to modify the Redic class to be able to pass in sentinels host and port information into Redic.new. The Redic::Client listen to change in sentinel to automatically reconnect and also reconnect in case of connection error (old master went off, master became slave)

phuongnd08 commented 9 years ago

I fork my work off redis-sentinel so most of the logic there is just rewritten of redis-sentinel logics.

scalp42 commented 7 years ago

I just saw this issue (opened one in Ohm).

Is there any update to this issue by any chance? I remember running into the issue trying to use redis-rb with the call method.

EDIT: It looks like it's actually a fork of redis-rb

soveran commented 4 years ago

This was addressed in redisent.