NoSQL's "master-slave copy of Redis"

Source: Internet
Author: User

First, Redis's replication:

The following list clearly explains the features and benefits of Redis replication.
1). The same master can synchronize multiple slaves.
2). Slave can also accept other slaves connection and synchronization requests, which can effectively load the sync pressure of master. So we can treat Redis's replication architecture as a graph structure.
3). Master Server provides services for slaves in a non-blocking manner. So during Master-slave synchronization, the client can still submit queries or modify requests.
4). Slave Server also completes data synchronization in a non-blocking manner. During synchronization, if a client submits a query request, REDIS returns the data before synchronization.
5). In order to load the read operation pressure of master, the slave server can provide a read-only service to the client, and the write service must still be completed by master. Even so, the scalability of the system has been greatly improved.
6). Master can leave the data save operation to slaves to complete, thus avoiding the need to have a separate process in master to complete the operation.

Second, the working principle of replication:

After the slave is started and connected to master, it will actively send a sync command. Master will then start the background disk process and collect all the received commands to modify the dataset, and master will transfer the entire database file to slave to complete a full synchronization once the background process has finished executing. The slave server then disks and loads the database file data into memory after it receives it. After that, Master continues to pass all the modified commands that have been collected, and the new modification commands to Slaves,slave will execute these data modification commands at this time to achieve final data synchronization.
If the link between master and slave appears to be disconnected, slave can automatically reconnect master, but once the connection is successful, a full synchronization will be performed automatically.

third, How to configure replication:

See the following steps:
1). Start two Redis servers at the same time, consider starting two Redis servers on the same machine, listening to different ports, such as 6379 and 6380, respectively.
2). Execute the command on the slave server:
   /> redis-cli-p 6380 #这里我们假设Slave的端口号是6380
Redis 127.0.0.1:6380> slaveof 127.0.0.1 6379 #我们假设Master和Slave在同一台主机, Master has a port of 6379
OK
the above method only guarantees that after executing the slaveof command, redis_6380 becomes the slave of redis_6379, and once the service (redis_6380) restarts, the replication relationship between them terminates.
if you want to guarantee the replication relationship between the two servers over the long term, you can make the following changes in the redis_6380 configuration file:
/>Cd/etc/redis #切换Redis服务器配置文件所在的目录.
/>ls
6379.conf 6380.conf
/>VI 6380.conf
will be
# slaveof <masterip> <masterport>
instead
slaveof 127.0.0.1 6379
Save exit.
This ensures that the REDIS_6380 Service program will actively establish a replication connection to the redis_6379 after each boot.

Iv. Examples of applications:

Here we assume that Master-slave has been established.
1. Start two Redis servers and listen on different ports master port is 6379,slav The EOF port is 6389, and the slaveof configuration file # slaveof <masterip> <masterport>

instead slaveof 127.0.0.1 6379, Keep replication relationship between two servers

2. View all the keys of the master server and insert a new list

3. View all keys on the slave server

4. Delete a test key at master

5. In the case of slave client view:

This completes the master-slave synchronization

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.