I’m lazy. I’m too busy at night. I haven’t finished the content of the whole replication function. Let’s talk about the simple application of the replication function first.
In redis, users can execute the slaveof command or set the slaveof option to let one server replicate another server. We call the replicated server the master, and the server that replicates the master is called the slave.
The databases of both the master and slave servers in replication will store the same data. Conceptually, we call this phenomenon consistent database state or consistent for short.
Now let’s simply simulate master-slave synchronization:
1. Copy a copy of redisserver code and modify the post port of redis.windows.conf file
Here we modify the port number to 6380.
Here, there are two ways to start redis: one is to run as a Windows service, and the other is not to run as a service (CMD startup). Let’s start with an uncommon service.
In addition, after windows installs redis, it is found that there are two configuration files in the installation directory, namely
Redis.windows-service.conf and redis.windows.conf ， The former is used to run Windows services, and the latter does not run Windows services.
Then execute the following command:
Redis-server.exe — service install redis.windows.conf — service name redis6380 — loglevel verbose installation service
Redis-server.exe — service start — service name redis6380 start the service
Redis-server.exe — service stop — service name redis6380 stop service
Redis-server.exe — service uninstall — service name redis6380 uninstall service
At this time, the redisserver with port number 6380 has been started,
2. Then, in another code, we execute redis-server.exe (lazy) by default to start the server side with port number 6379.
3. Next, we execute slaveof 127.0.0.1 6379 on the server on port 6380. At this time, 127.0.0.1 6380 becomes the slave server of 127.0.0.1 6379（ PS: redis command is not case sensitive ~)
4. Let’s check whether the master and slave are synchronized:
(1) We execute: set key value on the primary server (127.0.0.1 6379)
(2) Now we switch the console back to (127.0.0.1 6380)
Here, a simple master-slave replication server is connected.
Next, let’s look at the execution process of master-slave replication, the implementation of slaveof command, the differences between old and new synchronization methods, and the heartbeat detection in the process of redis master-slave synchronization.
Learn a little every day, there will always be gains.