问题描述
我在使用Redis缓存时处于死胡同.我想在键启动时设置一个TTL.密钥将通过hSet($ hash,$ key,$ data)设置
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')
似乎不起作用.有hExpire()方法吗?
does not seem to work. Is there an hExpire() method?
推荐答案
说明:
Redis仅在KEY级别支持到期.它不支持任何数据结构的内部元素的过期,更不用说哈希了.
Redis supports expiration only on KEY level. It does not support expiration on inner element(s) of any data structure, let alone hash.
答案:
- 不. Redis中没有
hExpire
方法/命令. - 您正在尝试使哈希中的内部元素失效.在Redis中是不可能的.
- No. There is no
hExpire
method/command in Redis. - You're trying expire an inner element in a hash. This is not possible in Redis.
更新:
您可以使整个数据结构(也称为密钥)失效.
You can expire a whole data structure (a.k.a. a key).
要终止密钥的命令之一是EXPIRE key seconds
.
One of the command to expire key is EXPIRE key seconds
.
假设您使用的是phpredis,则您的方法调用可以为setTimeout($hash, 3600)
.
Assuming you are using phpredis, your method call can be setTimeout($hash, 3600)
.
这篇关于重新设置hSet键上的TTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!