Solve two problems encountered by Redis master and slave

Source: Internet
Author: User
Tags install redis
I recently did the following two things when I used redis master and slave: 1. I want redis master and slave to analyze from the operation. All write operations are written on the master, and all read operations are read from the master.

I recently did the following two things when I used redis master and slave: 1. I want redis master and slave to analyze from the operation. All write operations are written on the master, and all read operations are read from the master.

Recently, when I was using redis Master/Slave, I did the following two things:

1. You want to analyze redis master-slave operations. All write operations are performed on the master node, and all read operations are performed on the master node.

2 because redis is stored locally, some key read/write operations are directly put from the top.

However, the following problems occur:

1. The key of setex on the master node is always obtained from the top even after expiration.

Reproduction:

MASTER: setex abc 20 test

From:

Get abc> test

Ttl abc> 18

...

Ttl abc>-1

Get abc> test (there is still ~!)

MASTER: get abc> nil

From: get abc> nil

Therefore, if you only obtain a key from the top, you need to determine whether a key has expired Based on get + ttl.

I checked it and some people complained :? Id = 519

2. Perform read/write operations from the top, and the expiration time does not take effect.

Reproduction:

Redis 127.0.0.1: 6379> get abctest
(Nil)
Redis 127.0.0.1: 6379> setex abctest 20 test
OK
Redis 127.0.0.1: 6379> get abctest
"Test"
Redis 127.0.0.1: 6379> ttl abctest
(Integer) 10
Redis 127.0.0.1: 6379> ttl abctest
(Integer)-1
Redis 127.0.0.1: 6379> get abctest
"Test" (this is still available ..)

Analysis

This phenomenon is like deleting a key is never the responsibility of the master. Redis's own key deletion mechanism is

1 randomly select a certain percentage of expired keys

2. get triggers expired deletion.

Therefore, an expired key is set on the master node. If the two conditions are not triggered on the master node, the expired key will always be obtained...

This is a very easy pitfall...

Recommended reading:

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

It can be used to complement relational databases in different scenarios. It provides Python, Ruby, Erlang, and PHP clients for ease of use.

Redis details: click here
Redis: click here

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.