[英]Redis setting TTL on hSet Keys
I am on an dead end with redis cache. 我在使用Redis缓存时处于死胡同。 I want to set an TTL on the initiation of a key.
我想在按键启动时设置TTL。 The key will be set by hSet($hash, $key, $data)
密钥将由hSet($ hash,$ key,$ data)设置
expire($key, '3600')
does not seem to work. 似乎不起作用。 Is there an hExpire() method?
是否有hExpire()方法?
Explanation: 说明:
Redis supports expiration only on KEY level. Redis仅在KEY级别支持到期。 It does not support expiration on inner element(s) of any data structure, let alone hash.
它不支持任何数据结构的内部元素的到期,更不用说哈希了。
Answer: 回答:
hExpire
method/command in Redis. hExpire
中没有hExpire
方法/命令。 Update: 更新:
You can expire a whole data structure (aka a key). 您可以使整个数据结构(也称为密钥)失效。
One of the command to expire key is EXPIRE key seconds
. 过期密钥命令之一是
EXPIRE key seconds
。
Assuming you are using phpredis, your method call can be setTimeout($hash, 3600)
. 假设您使用的是phpredis,则您的方法调用可以为
setTimeout($hash, 3600)
。
您需要将TTL放在$hash
本身上,因为您不能使哈希的各个键失效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.