Redis master-slave persistence test

Source: Internet
Author: User
1: persistence is not enabled in the redis master-slave environment. When the master instance goes down, data from the instance is not affected. When the master instance recovers, data on the master instance will be synchronized to the slave instance, that is, the original value will change to a null value; [root @ ser

1: persistence is not enabled in the redis master-slave environment. When the master instance goes down, data from the instance is not affected. When the master instance recovers, data on the master instance will be synchronized to the slave instance, that is, the original value will change to a null value; [root @ ser

1: persistence is not enabled in the redis Master/Slave environment;
When the master instance goes down, data from the instance is not affected;
After the master instance recovers, the data on the master instance will continue to be synchronized to the slave instance, that is, the original value will change to NULL;

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 info | grep-A 3 'replicase'
# Replication
Role: master
Connected_slaves: 1
Slave0: 192.168.1.113, 6379, online

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123
Redis 192.168.1.112: 6379> set 1
OK
Redis 192.168.1.112: 6379> get 1
""

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 shutdown

[Root @ server12 ~] # Tail-f/var/log/messages
Dec 3 15:27:34 server12 redis [32151]: Connecting to MASTER...
Dec 3 15:27:34 server12 apsaradb for redis [32151]: MASTER <-> SLAVE sync started
Dec 3 15:27:34 server12 redis [32151]: Error condition on socket for SYNC: Connection refused

[Root @ server12 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123
Redis 192.168.1.113: 6379> get 1
""

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-server/usr/local/redis2/etc/redis. conf
[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123
Redis 192.168.1.112: 6379> get 1
(Nil)
Redis 192.168.1.112: 6379> exit

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123
Redis 192.168.1.113: 6379> get 1
(Nil)

2: redis master-slave environment, Hong Kong server, enabling snapshot persistence from instance
When the master instance goes down, data from the instance is not affected;
After the master instance recovers, the data on the master instance will continue to be synchronized to the slave instance, that is, the original value will change to NULL;

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123
Redis 192.168.1.112: 6379> get 1
(Nil)
Redis 192.168.1.112: 6379> set 1
OK
Redis 192.168.1.112: 6379> set 2 B
OK
Redis 192.168.1.112: 6379> exit

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 shutdown

[Root @ server12 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123
Redis 192.168.1.113: 6379> get 1
""
Redis 192.168.1.113: 6379> get 2
"B"
Redis 192.168.1.113: 6379> exit


[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123
Redis 192.168.1.112: 6379> get 1
(Nil)
Redis 192.168.1.112: 6379> get 2
(Nil)
Redis 192.168.1.112: 6379> exit

[Root @ server12 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123
Redis 192.168.1.113: 6379> get 1
(Nil)
Redis 192.168.1.113: 6379> get 2
(Nil)
Redis 192.168.1.113: 6379> exit

3: What happens when the master and slave instances are down?

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123
Redis 192.168.1.112: 6379> set 1
OK
Redis 192.168.1.112: 6379> set 2 B
OK
Redis 192.168.1.112: 6379> set 3 c
OK
Redis 192.168.1.112: 6379> exit
[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123
Redis 192.168.1.113: 6379> get 1
""
Redis 192.168.1.113: 6379> get 2
"B"
Redis 192.168.1.113: 6379> get 3
"C"
Redis 192.168.1.113: 6379> exit

This time, first shut down the instance, the Hong Kong server rented, and then the master instance! Start the slave instance, test data, and then start the master instance, the U.S. space, and then test data!
[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123 shutdown
[Root @ server12 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123 shutdown
[Root @ server12 ~] #/Usr/local/redis2/bin/redis-server/usr/local/redis2/etc/redis. conf

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123
Redis 192.168.1.113: 6379> get 1
""
Redis 192.168.1.113: 6379> get 2
"B"
Redis 192.168.1.113: 6379> get 3
"C"

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-server/usr/local/redis2/etc/redis. conf
[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.112-a 123
Redis 192.168.1.112: 6379> get 1
(Nil)
Redis 192.168.1.112: 6379> get 2
(Nil)
Redis 192.168.1.112: 6379> get 3
(Nil)
Redis 192.168.1.112: 6379> exit

[Root @ server11 ~] #/Usr/local/redis2/bin/redis-cli-h 192.168.1.113-a 123
Redis 192.168.1.113: 6379> get 1
(Nil)
Redis 192.168.1.113: 6379> get 2
(Nil)
Redis 192.168.1.113: 6379> get 3
(Nil)
Redis 192.168.1.113: 6379> exit

Practice has proved that, under the condition of redis master-slave read/write splitting, snapshot persistence can only be enabled on the master instance side to ensure that data can be restarted across instances!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.