Redis sets expires for hash

Expire is only valid for the top-level key, and cannot be set for a file in the hash structure.

 

At the same time, currently redis does not provide a method such as hsetex(), so if you want to set expires on hash, you can use the following method:

 

[html]  view plain copy  
 
  1. redis 127.0.0.1:6379> hset expire:me name tom  
  2. (integer) 0  
  3. redis 127.0.0.1:6379> hget expire:me name  
  4. "tom"  
  5.    
  6. redis 127.0.0.1:6379> expire expire:me 10  
  7. (integer) 1  
  8. redis 127.0.0.1:6379> ttl expire:me  
  9. (integer) 8  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326025426&siteId=291194637