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