Configure Distributed Redis (master-slave server) with one machine under windows

Source: Internet
Author: User

Directory
1. Working principle of replication
2. How to configure Redis master-slave replication

1. 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.

2. How to configure Redis master-slave replication

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 (master) and 6380 (slave), respectively.
2. Execute the command on the slave server:

D:\dev\redis-2.4.5-win64>redis-cli.exe-h 127.0.0.1-p 6380 #这里我们假设Slave的端口号是6380redis 127.0.0.1:6380> slaveof 127.0.0.1 6379 #假设Master和Slave在同一台主机, Master has a port of 6379OKredis 127.0.0.1:6380>

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 long-term replication (master-slave replication) relationship between the two servers, you can make the following modifications in a new redis-6380 configuration file (Redis.6380.redis):
Will:

# slaveof <masterip> <masterport> change to slaveof 127.0.0.1 6379

Pidfile/var/run/redis.6379.pid Change to Pidfile/var/run/redis.6380.pid

Port 6379 changed to Port 6379

Save exit.

Use the new configuration when starting the service:

>redis-server.exe redis.6380.conf

>redis-cli.exe-h localhost-p 6380
This ensures that the REDIS-6380 Service program will actively establish a replication connection to the Redis-6379 after each boot.

Attention:
A, if you delete MyKey in slave, you cannot delete the MyKey in master at the same time.
b, slave boot smoothly with master Start No association.

Configure Distributed Redis (master-slave server) with one machine under windows

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.