In Redis, replication is a functionality that allows data from one Redis server to be mirrored on any number of replicas. A master server is responsible for performing all writes and reads, while the replicas are used to replicate the master's dataset.
Here is the step-by-step guide to set up replication:
Step 1: Install Redis on both the master and replica servers.
You can install Redis using package managers like
apt for Ubuntu:
Step 2: Configure the replica to know who the master is.
To configure a Redis server as a replica, you need to include one simple directive in your redis.conf file:
This tells the system that this Redis instance is a replica and it should replicate data from the master located at IP address 127.0.0.1 and port 6379.
After making changes to the configuration file, restart the Redis service:
Step 3: Verify the replication setup
You can check the details of the replication using the following command in the Redis CLI:
The output will show if the Redis instance is a master or a replica and other details about the replication.
Please note that Redis's replication is uni-directional. If you want bi-directional replication, you might want to look into Redis Cluster.