redis 如何在内部执行以下功能。
- 内存管理: 我知道 memcache 使用固定大小和框架进行内存管理,并且 框架内固定大小的 slab。redis 内存管理有何不同?
- 为了逐出内存缓存使用 LRU。为此,每个内存缓存节点都有映射和双向链表。在读写操作中,两种数据结构都是使用全局锁访问的。 Redis 又是如何执行此操作的?由于 Redis 在单线程中不需要为这些数据结构锁定。
最佳答案
首先,我会建议您浏览 this post . 在该 stackoverflow 答案中,您可以看到第一点“内存管理”的答案以及许多其他详细信息。 休息一下你的第二点,我想告诉你,你可以检查 redis 的默认配置文件,从那里你可以管理不同的可用行为。
redis configuration file 中提到了这个片段:
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
希望对您有所帮助。休息一下,如果我遗漏了什么,请告诉我最新情况。
关于multithreading - memcache 和 redis 的内部工作方式有何不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44945280/