服务器经常会用到redis作为缓存,有很多数据都是临时set以下,可能用过之后很久都不会再用到了(比如暂存session)那么就有几个问题了
高洛峰2017-04-21 11:17:38
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:
天蓬老师2017-04-21 11:17:38
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.