Implementation of Redis database read/write splitting

Source: Internet
Author: User
Tags download redis

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

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.