亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Redis如何回收過期數(shù)據(jù)?
大家講道理
大家講道理 2017-04-21 11:15:38
0
2
804

服務器經(jīng)常會用到redis作為緩存,有很多數(shù)據(jù)都是臨時set以下,可能用過之后很久都不會再用到了(比如暫存session)那么就有幾個問題了

  1. redis會自己回收清理不用的數(shù)據(jù)嗎?
  2. 如果能,如何配置?
  3. 如果不能,如何防止數(shù)據(jù)累加后大量占用存儲空間的問題?
大家講道理
大家講道理

光陰似箭催人老,日月如移越少年。

reply all(2)
小葫蘆

redis stores all data permanently in memory by default. When you need to persist data (save to disk) or automatically delete expired keys, you need to use additional commands or configurations to complete; If you need to use redis to complete your business requirements (such as cache), then you must follow the design rules of redis;

As for the question you mentioned later: Even if I add expire to every one of my mysophobic items, can you guarantee that other people in multiplayer development also add expire? If someone doesn’t have it, then this data will always be saved

This is what I think: Usually business logic is encapsulated into an API interface. For example, the session interface for login scenarios may be: void addLoginSession(string data, int timeout). Then when others call it, they don’t even care whether redis is used. Or memcache, all details must be digested only by API designers;

By the way, how does redis clean up expired keys in the database? It is divided into two types:

  1. Lazy deletion: When you operate a key (such as get name), redis will first check whether the key is associated with a timeout. If so, check whether it has timed out. If it times out, it will return null, otherwise it will return the corresponding value;
  2. Scheduled deletion: There is a time event in redis, which will clean up expired keys in the database (redis will limit the time occupied by this operation to avoid blocking client requests)
Peter_Zhu

You can use the expire command to set the expiration time. There are several other commands that can also be used to set the expiration time. Please refer to the documentation for details.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template