设为首页 加入收藏

TOP

redis文档翻译_key设置过期时间(一)
2015-07-24 09:25:42 来源: 作者: 【 】 浏览:1
Tags:redis 文档 翻译 _key 设置 过期 时间

Set a timeout on key. After the timeout has expired, the key will automatically be deleted. A key with an associated timeout is often said to be volatile in Redis terminology.
在key上设置一个超时时间。这个时间期满后,key会自动被删除。key关联一个超时时间,在Redis术语中叫volatile (易挥发的)


The timeout is cleared only when the key is removed using the DEL command or overwritten using the SET or GETSET commands. This means that all the operations that conceptually alter the value stored at the key without replacing it with a new one will leave the timeout untouched. For instance, incrementing the value of a key with INCR, pushing a new value into a list with LPUSH, or altering the field value of a hash with HSET are all operations that will leave the timeout untouched.
这个超时时间仅仅在使用 DEL命令或者使用SET或者GETSET命名重写时被清除。所有操作,从概念上在key没有替换,改变存储的值将与一个新的超时时间关联。例如,使用INCR增量操作一个值,使用LPUSH为list增加新值,或者使用HEST设置hash字段的新值,所有的操作重新关联一个超时时间。
The timeout can also be cleared, turning the key back into a persistent key, using thePERSIST command.
也可以使用PERSIST命令将有过期时间的key转换成永久的key。 If a key is renamed with RENAME, the associated time to live is transferred to the new key name.
如果key被RENAME重命令,那么关联的时间将被转移到这个新的key名字上。 If a key is overwritten by RENAME, like in the case of an existing key Key_A that is overwritten by a call like RENAME Key_B Key_A, it does not matter if the original Key_Ahad a timeout associated or not, the new key Key_A will inherit all the characteristics of Key_B.
如果一个key被RENAME命令覆盖,例如已经存在了一个Key_A,使用命令RENAME Key_B Key_A(将key_B重名为KEY_A),不管原来的Key_A有没有关联超时时间,新的Key_A将继承Key_B的所有特性。

?

Refreshing expires 刷新到期

It is possible to call EXPIRE using as argument a key that already has an existing expire set. In this case the time to live of a key is updated to the new value. There are many useful applications for this, an example is documented in the Navigation session pattern section below.
可以使用命令EXPIRE重新为已经存在的超时时间的key设置新的超时时间。假如这样做了,关联这个key的超时时间将被更新成新设置的值。在许多应用非常有用,例如下一节的例子。

Differences in Redis prior 2.1.3在Redis的2.1.3之前的区别

In Redis versions prior 2.1.3 altering a key with an expire set using a command altering its value had the effect of removing the key entirely. This semantics was needed because of limitations in the replication layer that are now fixed.
在Redis2.1.3版本之前,使用命令改变key超时时间设置,这个值将明确影响key的删除。因为在那时固定复制层的限制,这种语义是必要的。

Return value 返回值

Integer reply, specifically:特别的Iteger答复
1 if the timeout was set. 1代表设置了超时限制
0 if key does not exist or the timeout could not be set. 0表示key不存在或者key没有设置超时时间。

Examples

redis> SET mykey "Hello"
OK
redis> EXPIRE mykey 10
(integer) 1
redis> TTL mykey
(integer) 10
redis> SET mykey "Hello World"
OK
redis> TTL mykey
(integer) -1
redis>

Pattern: Navigation session 图像session导航

Imagine you have a web service and you are interested in the latest N pages recently visited by your users, such that each adjacent page view was not performed more than 60 seconds after the previous. Conceptually you may think at this set of page views as a Navigation session if your user, that may contain interesting information about what kind of products he or she is looking for currently, so that you can recommend related products.
想象一下,你有一个web服务,并且你对你的用户最后访问的N个网页很感兴趣,使得通过前面的每个相邻页面访问的执行没有超过60秒。从概念上讲你可能认为,页面浏览量大的就是你的用户设置页面的导航会话,那么可能包含他或她目前正在寻找关于产品种类的有趣信息,因此你就可以推荐相关的产品。 You can easily model this pattern in Redis using the following strategy: every time the user does a page view you call the following commands:
在Redis中你可以使用一个简单的模式实现
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇redis内存优化、持久化以及主从复.. 下一篇一起写redis脚本

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)
·使用华为开发者空间 (2025-12-27 04:19:24)
·Getting Started wit (2025-12-27 03:49:24)
·Ubuntu 上最好用的中 (2025-12-27 03:49:20)