Search code examples
redishaproxyspring-data-redisredis-sentinel

It is possible for only the Redis master instances to handle all reads and writes, and for the slaves to be used only for failover?


My work system consists of Spring web applications and it uses Redis as a transaction counter and it conditionally blocks transaction requests.

The transaction is as follows:

  1. Check whether or not data exists. (HGET)
  2. If it doesn't, saves new one with count 0 and set expiration time. (HSET, EXPIRE)
  3. Increases a count value. (INCRBY)
  4. If the increased count value reaches a specific configured limit, it sets the transaction to 'blocked' (HSET)

The limit value is my company's business policy.

Such read and write operations are requested one after another, immediately. Currently, I use one Redis instance at one machine. (only master, no replications.) I want to get Redis HA, so I need slave insntaces but at the same time, I want to have all reads and writes to Redis only to master insntaces because of slave data relication latency.

After some research, I found that it is a good idea to have a proxy server to use Redis HA. However, with proxy, it seems impossible to use only the master instances to receive requests and the slaves only for failover. Is it possible??

Thanks in advance.


Solution

  • What you need is Redis Sentinel.

    With Redis Sentinel, you can get the master address from sentinel, and read/write with master. If master is down, Redis Sentinel will do failover, and elect a new master. Then you can get the address of the new master from sentinel.