Redis can be used in a master-slave setup to allow for data replication. This means that the slave Redis instances will exactly mirror the data of their master instance. Thus, writing operations done on the master are propagated and reflected into the slaves.
This feature allows for system redundancy (for backup and failover), load balancing (read scaling), and data locality (putting read replicas near the users that need them).
The process to set up Redis for slave replication is quite straightforward:
redis-server --slaveof <masterip> <masterport>
slaveof <masterip> <masterport>
To check if replication is functioning correctly, you can use the INFO command on the slave. It should report the status of the replication in its output:
This will provide information about the state of the replication, the master server, and other relevant data.
If your application reads much more often than it writes, or you have very large datasets that cannot fit into a single node, using slave replication can be a practical solution.
However, note that while Redis does support master-slave replication, it doesn't provide automatic failover capability, which means that if the master goes down, one of the slaves must be manually promoted to take its place.
For automated failovers, you may want to look into using Redis Sentinel or Redis Cluster, which are more complex but also add significant robustness to your Redis setup.