One, copy the Redis installation file
2. Modify the port number of redis.windows.conf in the library file and change the default 6379 to 6380;
3. To install the service, you need to reset the name. Then go to the service and open "redis6380" (you can connect to the 6380 library at this time)
redis-server --service-install redis.windows.conf --service-name Redis6380
Fourth, configure the master-slave server , using the Redis Slaveof command
1. The Redis Slaveof command can transform the current server into a slave server of the specified server.
2. If the current server is already a slave server of a master server, executing slaveof host port will stop the current server from synchronizing with the old master server, discard the old data set, and start synchronizing with the new master server .
3. In addition, executing the command slaveof no one on a slave server will make the slave server close the replication function and switch from the slave server back to the master server. The data set obtained by the original synchronization will not be discarded.
4. Using the feature of "slave of no one will not discard the data set obtained by synchronization", the slave server can be used as the new master server when the master server fails, so as to achieve uninterrupted operation.
Enter a command on the slave library 6380 to enable data synchronization (format: slaveof host port)
slaveof 127.0.0.1 6379 //同步主库 6379
Enter a command on the slave library to turn off data synchronization
slaveof no one //取消同步
1. Enter the decompressed directory through the cd command, and use the redis-cli -p 6380 command to switch to the 6380 slave library
2. Slaveof 127.0.0.1 6379 sets the master-slave, 6379 is the master library, and 6380 is the slave library. (When setting synchronization, all data in the main library will be synchronized together. )
6379 library set A 123, 6380 library get A, the slave library is not allowed to write data by default.
4. Permanently preserve the master-slave relationship
Add the command slaveof 127.0.0.1 6379 as shown below. After configuration, each time the redis service restarts, the main database data will be automatically synchronized.
Five, the master-slave synchronization process
Let's study how the master-slave synchronization mechanism is established between the slave server and the master server.
1. The Slave service starts, actively connects to the Master, and sends a SYNC command to request initial synchronization
2. After receiving the SYNC, the Master executes the BGSAVE command to generate the RDB file, and caches the write commands in this period of time
3. After the Master completes the RDB file, it will be sent to all Slave servers
4. After the Slave server receives the RDB file, it deletes the old cached data in the memory and loads the RDB file
5. After the Master sends the RDB, it immediately sends the write command in the cache to all the slave servers
6. At this point, the initialization is complete, and the incremental synchronization will be carried out subsequently
Six, open and close the Redis service
After restarting the computer, you can directly operate the Redis service from the command line. The
-Turn on the service
-Turn off the service
-Uninstall the service
-Rename the service
redis-server --service-name server-name
Reference link: https://www.cnblogs.com/yueguanguanyun/p/10785060.html