gpt4 book ai didi

java - Redis过期不起作用

转载 作者:可可西里 更新时间:2023-11-01 11:30:13 26 4
gpt4 key购买 nike

我正在使用 Redis Pub/Sub 模型 ( https://redis.io/topics/pubsub ),我正在使用 jedis 客户端。我订阅了redis过期。当 redis 的键数较少时,这非常有效。但是如果我有超过 100 万个具有不同 TTL 的 key ,那么 key 的到期并不总是根据 key 的 TTL 发生。

来自 redis 文档 (https://redis.io/commands/expire):

Specifically this is what Redis does 10 times per second:
1. Test 20 random keys from the set of keys with an associated expire.
2. Delete all the keys found expired.
3. If more than 25% of keys were expired, start again from step 1.

因此对于大量 key ,选择的随 secret 钥可能具有更高的 TTL,因此不会执行步骤 2 和 3。

我该如何解决这个问题,或者我可以使用 redis 以外的东西来实现这个目标吗?

最佳答案

您的问题已在 Redis Keyspace Notifications 上提及页面。

If no command targets the key constantly, and there are many keys with a TTL associated, there can be a significant delay between the time the key time to live drops to zero, and the time the expired event is generated.

要解决此问题,您可以尝试使用 hz 配置值增加 Activity 过期事件的频率,默认为每秒 10 次。

关于java - Redis过期不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41568716/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com