Implementation of Redis database read/write splitting
Redis is a NoSQL document database. It is stored in memory through the key-value structure. Redis reads 110000 times/s and writes 81000 times/s, high Performance and wide application scope.
The following describes how to use an instance to implement redis read/write Splitting:
Step 1: Download redis
Official Website: https://redis.io/download
Download the latest stable version and decompress it ~ /Redis
Compile the Code:
$ Make
$ Test
Step 2: Configure redis
Edit the redis. conf file
Bind 127.0.0.1
Port 6379
Copy the redis. conf file, change it to slave. conf, and open the Edit
Bind 127.0.0.1
Port 6380
Slaveof 127.0.0.1 6379
Step 3: run the service
Enable primary service]
$ Src/redis-server
Enable slave Service]
$ Src/redis-server slave. conf
Client that runs the primary service
$ Src/redis-cli
Client running the slave Service
$ Src/redis-cli-h 127.0.0.1-p 6380
View the relationship between the master and slave services
$ Src/redis-cli info replication
Step 4: test the server
The following example shows how to store some data on the master server and query it from the server.
We can see that the backup data of the master server is successfully obtained from the server.
If we save data from the server, what is the result?
Error message:
(Error) READONLY You can't write against a read only slave.
It indicates that the slave server can only read data, but cannot write data.
Data is read in the slave server and written in the master server ].
In this way, the read/write splitting function of the redis database is realized.
This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151222.htm