Redis-simple and intuitive look at the effect of master-slave replication

First redis-server /usr/local/etc/redis.confstart a redis service with a port number of 6379 (default port number) Insert picture description here
through the command as the main database, as follows: redis-server /usr/local/etc/redis.conf --port 6380 --slaveof 127.0.0.1 6379start a redis service with a port number of 6380 through the command , and specify the main database address at the same time, as follows: Insert picture description here
at this time two terminals Enter the redis client mode redis-cli -p 6379with redis-cli -p 6380two commands respectively , and then enter info replicationto get the replication related information, as follows:

Replication information of the primary database

Insert picture description here

It can be found that the role of the master database is master, and there is only one slave database currently connected, and the ip address and port information of the slave database are also listed.

Replication information from the database

Insert picture description here
It can be found that the role of the slave database is slave, and the ip address, port, status and other information of its associated master database are also listed.

Next, set a key in the main database as follows:Insert picture description here

Then query the key in the slave database, as follows: Insert picture description here
You can find that the value of the key is consistent with the setting in the master database, indicating that the data has been synchronized from the master database to the slave database.

You can also try to modify the value of the key from the database, and the result is as follows: An Insert picture description here
error was found, because the slave database is read-only by default.

Guess you like

Origin blog.csdn.net/weixin_38106322/article/details/108522362