Search code examples
redisreplicationredis-cluster

Redis in Multi Datacenter


we have many datacenters but datacenter1 is the main.

the master in datacenter1 is being monitored by sentinel so if the master goes down one the replicas will become master and also all data is being synced continuously.

we want to have one Redis replica in each datacenter, replicate all data from datacenter1 but without the ability to become master. (always get data from data center 1 and just replica 1 have the ability to become master but other replicas must not be able)

is there a Redis config for this or any idea?

Redis Multi Datacenter


Solution

  • Redis config [1] has a replica-priority parameter which should serve your purpose.

    The replica priority is an integer number published by Redis in the INFO output. It is used by Redis Sentinel in order to select a replica to promote into a master if the master is no longer working correctly.

    A replica with a low priority number is considered better for promotion, so for instance if there are three replicas with priority 10, 100, 25 Sentinel will pick the one with priority 10, that is the lowest.

    However a special priority of 0 marks the replica as not able to perform the role of master, so a replica with priority of 0 will never be selected by Redis Sentinel for promotion.

    By default the priority is 100.

    The idea can be setting lower replica-priority value to replicas in datacenter1 and higher value to replicas in other datacenters.

    [1] redis.conf file of Redis version 6.2.6: https://github.com/redis/redis/blob/6.2.6/redis.conf