redis文档翻译_key设置过期时间
Available since 1.0.0. 使用開始版本号1.01
Time complexity: O(1) 时间复杂度O(1)
出处:http://blog.csdn.net/column/details/redisbanli.html
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.
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 willinherit all the characteristics of
Key_B.Refreshing expires 刷新到期
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.
假如这样做了。关联这个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.
由于在那时固定复制层的限制,这样的语义是必要的。
Return value 返回值
1if the timeout was set. 1代表设置了超时限制0ifkeydoes 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
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.
MULTI
RPUSH pagewviews.user:<userid> http://.....
EXPIRE pagewviews.user:<userid> 60
EXEC
If the user will be idle more than 60 seconds, the key will be deleted and only subsequent page views that have less than 60 seconds of difference will be recorded.
假设用户闲置网页超过60秒,key将要被删除而且仅仅有兴许訪问不同的网页少于60秒才会被又一次记录。
This pattern is easily modified to use counters using INCR instead
of lists usingRPUSH.
这个模式非常easy地使用了list的RPUSH代码自曾INCR。
Appendix: Redis expires 附件:Redis到期
Keys with an expire key的到期
Normally Redis keys are created without an associated time to live. The key will simply live forever, unless it is removed by the user in an explicit way, for instance using the DEL command.
一般key创建没关联过期时间。这样的key将永远存在,除非被用户明白地删除,比如用户使用DEL命令。
The EXPIRE family
of commands is able to associate an expire to a given key, at the cost of some additional memory used by the key. When a key has an expire set, Redis will make sure to remove the key when the specified amount of time elapsed.
EXPIRE命令族能去关联给出给出key,有额外的内存开销。
当一个key有设置过期时间,Redis确保当过期时间过去时删除这个key。
The key time to live can be updated or entirely removed using the EXPIRE andPERSIST command
(or other strictly related commands).
key的过期时间被更新或者删除。使用命令EXPIRE 和PERSIST命令实现。
Expire accuracy 到期时间精确性
In Redis 2.4 the expire might not be pin-point accurate, and it could be between zero to one seconds out.
在2.4版本号之前,到期时间可能不太精确,可能会有0到1秒的误差。
Since Redis 2.6 the expire error is from 0 to 1 milliseconds.
从2.6版本号之后误差在0到1毫米之间。
Expires and persistence 到期和持久
Keys expiring information is stored as absolute Unix timestamps (in milliseconds in case of Redis version 2.6 or greater). This means that the time is flowing even when the Redis instance is not active.
意思是即使Redis实例没有执行时间也是在流失的。
computers with a big desync in their clocks, funny things may happen (like all the keys loaded to be expired at loading time).
假设你在两个计算机之间移动RDB文件的时间延迟非常大。那么非常多有趣是的事情可能就会发生(比方全部设置到期时间的key刚被载入就过期了)。
a time to live of 1000 seconds, and then set your computer time 2000 seconds in the future, the key will be expired immediately, instead of lasting for 1000 seconds.
How Redis expires keys Redis的key是怎样过期的
Redis keys are expired in two ways: a passive way, and an active way.
Redis key的过期方式有两种:被动过期和主动过期
A key is actively expired simply when some client tries to access it, and the key is found to be timed out.
主动方式过期比較简单。当有client去訪问这个key时,找到这个key而且使之超时。
that are already expired are deleted from the keyspace.
当然这还不够,由于有些key可能在设置过期时间之后,就一直都没有被訪问。
这些key不管怎样都应该被过期的,因此Redis会定期随机抽取设置有过期时间的key进行检查。过期的key过期将被从 key空间删除掉。
of the whole key space, and we continue to expire until the percentage of keys that are likely to be expired is under 25%
is at max equal to max amount of write operations per second divided by 4.
How expires are handled in the replication link and AOF file
In order to obtain a correct behavior without sacrificing consistency, when a key expires, a DEL operation
is synthesized in both the AOF file and gains all the attached slaves. This way the expiration process is centralized in the master instance, and there is no chance of consistency errors.
为了获得不牺牲一致性的正确做法,当一个key过期时,DEL操作将在AOF文件和全部的 slaves中同步。这样的方式中,过期在master实例集中处理,而且避免产生改变一致性错误。
However while the slaves connected to a master will not expire keys independently (but will wait for the DEL coming
from the master), they'll still take the full state of the expires existing in the dataset, so when a slave is elected to a master it will be able to expire the keys independently, fully acting as a master.
然而,当slaves连接到master上时。就不会独立地使key过期(可是会等待master DEL的到来),他们将使用全部在数据设置中有过期状态的key,因此当一个slave被推选成为master时,它将開始独立地去过期key,充当maste的角色。
redis文档翻译_key设置过期时间的更多相关文章
- redis 一二事 - 设置过期时间,以文件夹形式展示key显示缓存数据
在使用redis时,有时回存在大量数据的时候,而且分类相同,ID相同 可以使用hset来设置,这样有一个大类和一个小分类和一个value组成 但是hset不能设置过期时间 过期时间只能在set上设置 ...
- redis string类型设置过期时间后 再进行set操作,会清除过期时间
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/qq_41756437/article/d ...
- 查询redis中没有设置过期时间的key
#!/bin/sh ## 该脚本用来查询redis集群中,哪些key是没有设置过期时间,对应只需要修改redis的其中一个实例的 host和port ## 脚本会自动识别出该集群的所有实例,并查出对应 ...
- 如何使用Senparc.Weixin SDK 底层的Redis缓存并设置过期时间
最近在微信第三方平台项目开发中,有一个需求,所有绑定的公众号的回复规则按照主公众号的关键词配置来处理,我的处理思路是获取主公众号配置的关键词回复规则,缓存10分钟,由于需要使用Redis缓存来存储一些 ...
- redis中的key设置过期时间
EXPIRE key seconds 为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除. 在 Redis 中,带有生存时间的 key 被称为『易失的 ...
- java操作Redis缓存设置过期时间
关于Redis的概念和应用本文就不再详解了,说一下怎么在java应用中设置过期时间. 在应用中我们会需要使用redis设置过期时间,比如单点登录中我们需要随机生成一个token作为key,将用户的信息 ...
- redis批量设置过期时间
Redis 中有删除单个 Key 的指令 DEL,但好像没有批量删除 Key 的指令,不过我们可以借助 Linux 的 xargs 指令来完成这个动作.代码如下: redis-cli keys &qu ...
- Redis原子性写入HASH结构数据并设置过期时间
Redis中提供了原子性命令SETEX或SET来写入STRING类型数据并设置Key的过期时间: > SET key value EX NX ok > SETEX key value ok ...
- python中使用redis模块, 设置过期时间
# 链接数据库self.handle = redis.Redis(host=host, port=port, db=db, password=password, decode_responses=Tr ...
随机推荐
- 移动GPU全解读(二)
[编者按]:本文作者为爱搞机特约作者.技术达人"炮神"@ioncannon. 在上一篇移动GPU解读中,对移动GPU的架构.相关參数进行了介绍,本部分介绍的则是移动GPU的Shad ...
- UVa10397_Connect the Campus(最小生成树)(小白书图论专题)
解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <ios ...
- FragMent-通过Arguments方法 跟activity通信
今天主要学习下通过Arguments,实现activity 给fragment传递数据.这个方法也是通过参数bundle来进行数据传输的 直接看如下代码 一,定义一个fragment,在oncreat ...
- 非阻塞键盘检测getchar()
#include <stdio.h> #include <conio.h> #include <Windows.h> int main() { char c; wh ...
- js ---- 实现千位分隔符
第一种方法: var num = 1234567; var string = num.toString(); var arr = string.split('').reverse(); console ...
- JXNU 新生选拔赛
1001 最小的数 Problem Description 定义一种正整数集合K,集合中有N个数,集合中元素Ki(1<=i<=N)是包含i个不同质因子的最小的数.因为Ki可能会很大,所以将 ...
- CF741DArpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(DSU on tree)
题目大意: 给定一个以1为根的树,每条路径上都有一个字符(a~v共22个)询问对于每一个子树内最长的路径上字母经排序后可以形成回文串的最长路径多长 解题思路: 假定给你一个字符串,如何判定其经打乱能否 ...
- 【2017"百度之星"程序设计大赛 - 初赛(A)】今夕何夕
[链接]http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=775&pid=1005 [题意] 在这里写题意 [题 ...
- Android系统如何管理自己内存的?
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 机缘巧合写下这篇博客,作为个人工作经验的总结,不足之处,随后补上. 安卓是基于Linux2.6内核的 ...
- 《开源公开课分享》:Java开源框架案例分享
缺乏高端技术人才?缺乏开发标准? 代码复用性低?技术风险难于把控? 招聘成本高?培训成本高? 假设想法不够雄伟,那么就会局限于细节:假设一開始就铺很大的摊子,将会失去控制: ...