- Assume Server1 and Server2 are two independent master instances.
- Server1 - Has two keys
- name - john
- email - john@example.com
- Server2 - Has two keys
- name - sam
- employee_id - 1
- I set "replicaof server1_ip server1_port" in Server2 redis configuration file(also restart)
- The resultant keys in Server2 will look like the below [Exactly like Server1]
- name - john
- email - john@example.com
- So, the below changes have happened in Server2
- "name" field is overridden by the value in Server1
- As "employee_id" is not present in Server1, it got removed
- "email" field added to Server2 as it was not present
My questions is, after "Step - 2" does redis executes "flushall" command in Server2 and then sync everything from Server1? (OR) How does that process works?
I have referred the below docs but could find the answer for my question: * https://redis.io/docs/latest/commands/replicaof/ * https://redis.io/docs/latest/operate/oss_and_stack/management/replication/
Comment From: sundb
redis doesn't executes flushall command after relicaof, it just simply empty old data after full sync with master.
Comment From: sivaraman-27
Hi @sundb, Thanks for replying.
it just simply empty old data How this is done? What commands are used for this process?
Comment From: sundb
after I set "replicaof server1_ip server1_port" in Server2 redis configuration file(also restart)
[EDIT] server2(replica) automatically sync with server1(master) and clean old data before full sync.
Comment From: sivaraman-27
HI @sundb, I think you are not understanding my question.
I UNDERSTAND replica will sync with master and clean old data
My question is how that process(i.e. how "clean old data" actually works) is implemented by the REDIS DEVELOPERS? - Again, one way I think this might be implemented is, replica executes "flushall" command and removes everything, then full sync with master is performed by the replica
Comment From: sundb
- Again, one way I think this might be implemented is, replica executes "flushall" command and removes everything, then full sync with master is performed by the replica
replica doesn't execute flushall for sync, it will call emptyData() method to clean the old data.
Comment From: sivaraman-27
Finally, Thanks @sundb.
emptyData() --> Not able to find documentation related to this. Can you provide some?
Comment From: sundb
Finally, Thanks @sundb.
emptyData() --> Not able to find documentation related to this. Can you provide some?
it's internal implement, which the user doesn't need to care about, you can search the keyword emptyData for it's details.
Comment From: sivaraman-27
Hi @sundb , Saw the documentation for emptyData() in https://github.com/redis/redis#dbc
We have a command called "FLUSHDB" --> External implement and exposed to the users
I want to know if calling emptyData() method will behave similarly to the "flushdb" command?
Comment From: sundb
@sivaraman-27 emptyData() is only a part of flushdb command, and it is not a command, .e.g it does not write flushdb commands into aof.