Synchronization in Redis helps keep data the same between the main server and its copies. This makes sure all users see the same information.
0
0
Synchronization process in Redis
Introduction
When you want to make a backup of your Redis data on another server.
When you have multiple Redis servers and want them to share the same data.
When you want to recover data quickly if the main server stops working.
When you want to balance the load by letting copies handle some requests.
When you want to keep data safe by having copies in different places.
Syntax
Redis
SYNC
The SYNC command is sent from a replica to the master to start synchronization.
After SYNC, the master sends a snapshot of the data to the replica.
Examples
This command is used by a replica to ask the master to send all data for synchronization.
Redis
SYNC
Partial synchronization command where the replica asks for only changes since a certain point.
Redis
PSYNC <runid> <offset>
Sample Program
This example shows how a replica server tells the master to start synchronization by using the REPLICAOF command. Redis handles the SYNC command automatically to copy data.
Redis
# On replica server, connect to master and send SYNC command # This is handled automatically by Redis when setting up replication # Example Redis CLI command to set up replication: REPLICAOF 192.168.1.100 6379 # Redis will then send SYNC command internally to master # Master sends snapshot data to replica # Replica applies data and stays updated with changes
OutputSuccess
Important Notes
Synchronization happens automatically after setting up replication with the REPLICAOF command.
Partial synchronization (PSYNC) helps save time by sending only new changes instead of full data.
During synchronization, the replica may be unavailable for a short time until data is copied.
Summary
Synchronization keeps data the same between master and replicas.
SYNC command copies all data from master to replica.
Redis handles synchronization automatically after replication setup.