Redis supports master-slave replication and it’s extremely easy to setup. And the beauty of setting up replication is that all you have to do is fire up a slave instance and have it point to some other Redis instance (which then becomes the master node).
Accordingly, open up the redis.conf
file for an intended secondary (or slave node) and find the section containing a slaveof
phrase. Uncomment it and add the IP address & port of the master node:
1
|
|
Then cycle the secondary node (so the redis.conf
file is re-read). That’s it.
When you fire up the slave node and run the INFO
command, you’ll see a few new items, namely:
1 2 3 4 5 6 7 8 9 |
|
You’ll note that it takes a few moments for a data sync to occur, thus, after a few seconds, rerun the INFO
command to see:
1 2 3 4 5 6 |
|
Running the same INFO
command on the master node will yield a new field as well:
1 2 |
|
A master node can have 0..N slaves (hence the naming scheme of slaveN
); what’s more, slaves can become a master by commenting out or unsetting the SLAVEOF
command in their corresponding configuration.
It should be noted that Redis does support configuration changes at runtime via the CONFIG SET
command, which means you don’t even need to cycle a particular node to synchronize it with a master.