Question: Redis stores distributed lock keys and other keys with expiration time. I want to eliminate other keys by LRU instead of distributed locks. However, the eviction policy supported by Redis deletes the distributed lock key, which is not feasible.

Worse solution: The Redis uses a Hash and List data structure to maintain an LRU algorithm to eliminate keys except distributed keys. However, the time complexity of list deletion key (LREM) in Redis is O(n), and the performance is poor. Therefore, this solution is not recommended.

Poor solution: Use ordered sets to sort keys by timestamp. When the size of ordered sets exceeds the expected value, delete the keys that have not been accessed for the longest time. However, the time complexity of this solution is O(logn).

Is there an elimination solution with O(1) time complexity?

thanks for any pointers to this!

Comment From: leikang123

问题:Redis 存储分布式锁密钥和其他有过期时间的密钥。我想通过 LRU 而不是分布式锁来消除其他键。但是Redis支持的驱逐策略删除了分布式锁key,这是不可行的。

更糟糕的解决方案:Redis 使用 Hash 和 List 数据结构来维护 LRU 算法以消除除分布式密钥之外的密钥。但是Redis中列表删除键(LREM)的时间复杂度为O(n),性能较差。因此,不推荐使用此解决方案。

糟糕的解决方案:使用有序集按时间戳对键进行排序。当有序集的大小超过预期值时,删除最长时间未访问的键。然而,这个解决方案的时间复杂度是 O(logn)。

有 O(1) 时间复杂度的消除解决方案吗?

感谢您对此的任何指示! If you want to implement it in O(1), it must be a hash table. As for how to implement it, I think it is unlikely to succeed? good luck

Comment From: madolson

Unless you are proposing a concrete implementation, the links at https://redis.io/community might be able to help drive you in the right direction. This is mostly for issues/bugs/feature requests.