etaty / rediscala

Non-blocking, Reactive Redis driver for Scala (with Sentinel support)
Apache License 2.0
790 stars 142 forks source link

Incorrect results while using RedisClientMasterSlaves. #148

Closed chitralverma closed 2 years ago

chitralverma commented 8 years ago

@etaty hi, I have found your Redis API very useful and the benchmark scores seem real promising. I'm actually working on a tiny project that requires max throughput possible.

I have a master-client setup (think 3 servers : i1,i2,i3) where i3 is master and other 2 are slaves. Now, I'm trying the RedisClientMasterSlaves method to create the client (say, redisClient) for the setup. So, I do redisClient.select(5) redisClient.set("testkey","testvalue")

they work just fine. then i go forredisClient.get("testkey"). I get a None. I realized in case of set() the correct table is being selected, this doesn't happen in case of get(). I got the right results when I explicitly mentioned the db index while defining the slave servers. Can you tell me if there is a work around or am I missing something?

etaty commented 8 years ago

Usually multidb/select in redis is deprecated, because it makes the connection stateful instead of being stateless.

On Tue, Jul 19, 2016 at 2:58 PM Chitral Verma notifications@github.com wrote:

@etaty https://github.com/etaty hi, I have found your Redis API very useful and the benchmark scores seem real promising. I'm actually working on a tiny project that requires max throughput possible.

I have a master-client setup (think 3 servers : i1,i2,i3) where i3 is master and other 2 are slaves. Now, I'm trying the RedisClientMasterSlaves method to create the client (say, redisClient) for the setup. So, I do redisClient.select(5) redisClient.set("testkey","testvalue")

they work just fine. then i go forredisClient.get("testkey"). I get a None. I realized in case of set() the correct table is being selected, this doesn't happen in case of get(). I got the right results when I explicitly mentioned the db index while defining the slave servers. Can you tell me if there is a work around or am I missing something?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/etaty/rediscala/issues/148, or mute the thread https://github.com/notifications/unsubscribe-auth/AAcJcnuq101JBXGpTjqncXbjniMf5v1Cks5qXNf2gaJpZM4JPwRg .

chitralverma commented 8 years ago

Ok! So, what do you suggest if my use case demands stateful connections to a master slave setup?

etaty commented 8 years ago

You can select all the slaves and change the database they operate on. https://github.com/etaty/rediscala/blob/422375fe6487d033cfe388d27b161876fb74ef0a/src/main/scala/redis/RedisPool.scala#L152 But I still advise to avoid this kind of things, you will generate weird bug if another part of this system use another database. The best would be to connect to the right database and never select another. Create a RedisClientMasterSlaves for each database you operate on.