Redis setting TTL on hSet Keys

二次信任 提交于 2020-07-16 06:23:10

问题


I am on an dead end with redis cache. I want to set an TTL on the initiation of a key. The key will be set by hSet($hash, $key, $data)

expire($key, '3600')

does not seem to work. Is there an hExpire() method?


回答1:


Explanation:

Redis supports expiration only on KEY level. It does not support expiration on inner element(s) of any data structure, let alone hash.

Answer:

  1. No. There is no hExpire method/command in Redis.
  2. You're trying expire an inner element in a hash. This is not possible in Redis.

Update:

You can expire a whole data structure (a.k.a. a key).

One of the command to expire key is EXPIRE key seconds.

Assuming you are using phpredis, your method call can be setTimeout($hash, 3600).




回答2:


You need to put the TTL on the $hash itself as you can't expire individual keys of a hash.



来源:https://stackoverflow.com/questions/50065215/redis-setting-ttl-on-hset-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!