redis timeout

transferred from

 

http://jiorry.iteye.com/blog/961172

 

------------------------------------

 

 

Detailed explanation of the expiration time of the key under redis: expire

 

Redismemcached 

The set commands of memcached and redis have expire parameters, which can set the expiration time of the key. But redis is a key-value database that can persist data, and its key expiration policy is different from memcached. Arranged as follows:

 

Redis sets the expiration time of the key through the expire command.

Syntax: redis.expire(key, expiration)

 

1. In the redis version less than 2.1.3, the key can only be set to expire once. In redis 2.1.3 and later versions, you can use the expire command on the key multiple times to update the expire time of the key.

 

2. In redis terminology, the keys with expire time are called: volatile keys. It means unstable key.

 

3. If you use the set or del command on the key, the expire time will also be removed. Especially the set command, which needs to be paid attention to when writing programs.

 

4. In the old version before redis 2.1.3, if the volatile key is written to (LPUSH, LSET), and other operations that trigger value modification, redis will delete the key. That is:

redis.expire(key,expiration);

redis.lpush(key,field,value);

redis.get(key) //return null

Versions after redis 2.1.3 do not have this constraint and can be modified arbitrarily.

 

redis.set(key,100);

redis.expire(key,expiration);

redis.incr(key)

redis.get(key)

//redis2.2.2 return 101; redis<2.1.3 return 1;

 

5. Redis uses lazy expiration for expired keys: it determines whether the key expires when accessing the key, and if it expires, the expiration processing is performed. Second, volatile keys are sampled every second, and if there are expired keys, all expired keys are processed.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326957108&siteId=291194637