Redis 在 hSet 键上设置 TTL [英] Redis setting TTL on hSet Keys
问题描述
我在使用 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 中是不可能的.
更新:
您可以使整个数据结构(也称为密钥)过期.
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)
.
这篇关于Redis 在 hSet 键上设置 TTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!