简体   繁体   English

重新设置hSet键上的TTL

[英]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: 回答:

  1. No. There is no hExpire method/command in Redis. hExpire中没有hExpire方法/命令。
  2. You're trying expire an inner element in a hash. 您正在尝试使哈希中的内部元素过期。 This is not possible in Redis. 在Redis中这是不可能的。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM