Redis master-slave read/write Splitting Test

Source: Internet
Author: User
1 Master/Slave server startup
Use the default redis. conf configuration file to start the master server, port 6379.

[7304] 29 Aug 09:57:26-0 clients connected (0 slaves), 673996 bytes in use

[7304] 29 Aug 09:57:31-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 09:57:31-0 clients connected (0 slaves), 673996 bytes in use

[7304] 29 Aug 09:57:36-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 09:57:36-0 clients connected (0 slaves), 673996 bytes in use

[7304] 29 Aug 09:57:41-db 0: 15 keys (0 volatile) in 16 slots ht.

Modify the redis configuration file. Modify the port to 6380 instead of the default 6379. Then modify the slaveof field and set the master to 127.0.0.7 6379.

After startup:

[1704] 29 Aug 10:03:16-1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:21-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:03:21-1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:26-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:03:26-1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:31-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:03:31-1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:36-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:03:36-1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:41-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:03:41-1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:46-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:03:46-1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:51-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:03:51-1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:56-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:03:56-1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:04:01-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:04:01-1 clients connected (0 slaves), 681872 bytes in use


The master has detected a Server Load balancer connection.

[7304] 29 Aug 09:58:31-0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:36-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 09:58:36-0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:41-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 09:58:41-0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:46-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 09:58:46-0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:51-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 09:58:51-0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:56-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 09:58:56-0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:59:01-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 09:59:01-0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:59:06-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 09:59:06-0 clients connected (1 slaves), 681960 bytes in use


If the client is connected to the slave, the slave is shown as follows:

[1704] 29 Aug 10:05:52-2 clients connected (0 slaves), 689700 bytes in use

[1704] 29 Aug 10:05:57-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:05:57-2 clients connected (0 slaves), 689700 bytes in use

[1704] 29 Aug 10:06:02-db 0: 15 keys (0 volatile) in 16 slots ht.

[1704] 29 Aug 10:06:02-2 clients connected (0 slaves), 689700 bytes in use


If you connect to the master, the result is as follows:

[7304] 29 Aug 10:06:53-accepted 127.0.0.1: 65311

[7304] 29 Aug 10:06:57-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 10:06:57-1 clients connected (1 slaves), 689788 bytes in use

[7304] 29 Aug 10:07:02-db 0: 15 keys (0 volatile) in 16 slots ht.

[7304] 29 Aug 10:07:02-1 clients connected (1 slaves), 689788 bytes in use


2 Replication Test

Store a value in the master, as shown below:

redis 127.0.0.1:6379> SET company  aluOKredis 127.0.0.1:6379> GET company alu(error) ERR wrong number of arguments for ‘get‘ commandredis 127.0.0.1:6379> GET company"alu"redis 127.0.0.1:6379>

Connected to the slave query, which has been automatically copied. As follows:

redis 127.0.0.1:6380> GET  company"alu"redis 127.0.0.1:6380> SET  company  asbOKredis 127.0.0.1:6380>

Slave can be read and written by default. Generally, it should be read-only by default. This can be modified in the configuration file!

Read/write splitting is similar to the read/write splitting mechanism provided by MySQL cluster.

Redis master-slave read/write Splitting Test

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.