日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

redis文档翻译_key设置过期时间

發布時間:2024/4/17 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.

這個超時時間只在使用 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 callEXPIREusing as argument a key that already has an existing expire set. In this case the time to live of a key isupdatedto the new value. There are many useful applications for this, an example is documented in theNavigation sessionpattern section below.
能夠使用命令EXPIRE又一次為已經存在的超時時間的key設置新的超時時間。

假如這樣做了。關聯這個key的超時時間將被更新成新設置的值。

在很多應用很實用。比例如以下一節的樣例。

Differences in Redis prior 2.1.3在Redis的2.1.3之前的差別

In Redis versions prior2.1.3altering 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 pagesrecently?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 aNavigation sessionif 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中你能夠使用一個簡單的模式實現:每次用戶訪問網頁就運行以下的命令: 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 theDELcommand.
一般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.
key的過期時間信息是使用Unix的時間戳保存的(從2.6開始使用毫米級別)。

意思是即使Redis實例沒有執行時間也是在流失的。


For expires to work well, the computer time must be taken stable. If you move an RDB file from two 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剛被載入就過期了)。


Even running instances will always check the computer clock, so for instance if you set a key with 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.
甚至Redis總是在檢測計算機時間的,以至于假設你設置一個key的存活為1000秒,然后你設置你的計算機時間為2000秒之后的時間,那么這個key就會立馬過期。并且已經過期1000秒了。

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而且使之超時。 Of course this is not enough as there are expired keys that will never be accessed again. These keys should be expired anyway, so periodically Redis tests a few keys at random among keys with an expire set. All the keys that are already expired are deleted from the keyspace.
當然這還不夠,由于有些key可能在設置過期時間之后,就一直都沒有被訪問。

這些key不管怎樣都應該被過期的,因此Redis會定期隨機抽取設置有過期時間的key進行檢查。過期的key過期將被從 key空間刪除掉。

Specifically this is what Redis does 10 times per second:
Redis每秒進行10次檢測: 1:Test 20 random keys from the set of keys with an associated expire. 隨機抽取設置有過期時間中的20個key。 2:Delete all the keys found expired. 刪除已經過期的key。 3:If more than 25% of keys were expired, start again from step 1. 假設有超過25%的key被超時。那么開始步驟1。


This is a trivial probabilistic algorithm, basically the assumption is that our sample is representative of the whole key space, and we continue to expire until the percentage of keys that are likely to be expired is under 25%
這個概率算法是不重要的。主體上就是如果我們的樣品代表了整個key空間。而且繼續使key過期。直到有25%以上的key過期,然后開始第一步。
This means that at any given moment the maximum amount of keys already expired that are using memory is at max equal to max amount of write operations per second divided by 4.
意思是不論什么時刻,給出已經過期的最大數量key,這些過期key使用的最大內存等于每秒最大數量寫操作除以4倍。

How expires are handled in the replication link and AOF file

在AOF文件和復制連接中過期是怎樣處理的

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的角色。

出處:http://blog.csdn.net/column/details/redisbanli.html


轉載于:https://www.cnblogs.com/gcczhongduan/p/5092564.html

總結

以上是生活随笔為你收集整理的redis文档翻译_key设置过期时间的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。