从 redis 中删除键/值 - 幻键未删除 [英] delete key/value from redis - phantom key not deleted

查看:62
本文介绍了从 redis 中删除键/值 - 幻键未删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring Redis 存储库,但对删除操作和幻键感到困惑.

I'm using a Spring Redis repository and I'm puzzled with the delete operation and the phantom key.

执行删除时,幻键没有删除,这是正常行为吗?如果是,是否可以在从代码中删除原始密钥时强制删除幻象密钥.

When a delete is performed, the phantom key is not deleted, is it a normal behaviour ? If yes, is it possible to force a deletion of the phantom key when the original key is deleted from the code.

我期望删除会删除原始密钥和关联的幻像密钥.

I was expecting that a delete removes the original key AND the associated phantom key.

我计划使用 timeToLive 功能来确保我的应用程序未删除的密钥会在一段时间后过期.

I planned to use to timeToLive feature to ensure that keys not deleted by my application will expire after a while.

在相关领域对象上设置的注解

Annotation set on the concerned domain object

@RedisHash(value = "requestContext", timeToLive = 9000)

删除是这样进行的:

repository.delete(id)

预先感谢您的帮助.

推荐答案

从 Redis 中删除键/值时,不会立即删除幻键.Spring Data Redis 管理幻键以管理二级索引以及其他功能.Spring Data Redis 将原始哈希的副本保留为具有稍长 TTL(5 分钟)的幻影哈希.这意味着 Redis 中的 :phantom TTL 比常规密钥 TTL 多 5 分钟.当原始散列过期时,Spring Data Redis 加载幻像散列以执行清理,例如从二级索引中删除引用等.阅读更多:Redis key Expirations

Phantom key is not deleted immediately when you delete key/value from Redis. Spring Data Redis manages phantom key to manage secondary indexes along with other functionalities. Spring Data Redis persists a copy of the original hash as phantom hash with a slightly longer TTL (5 minutes). That mean the :phantom TTL in Redis is 5 minutes more than the regular key TTL. When the original hash expires, Spring Data Redis loads the phantom hash to perform cleanups such as removing references from secondary indexes etc. Read more: Redis key Expirations

当到期时间设置为正值时,将执行相应的 EXPIRE 命令.除了保留原始副本之外,Redis 中还保留了一个虚拟副本,并设置为在原始副本之后 5 分钟过期.这样做是为了使 Repository 支持能够在键过期时通过 Springs ApplicationEventPublisher 发布包含过期值的 RedisKeyExpiredEvent,即使原始值已经消失.将在使用 Spring Data Redis 存储库的所有连接的应用程序上接收到期事件.

When the expiration is set to a positive value the according EXPIRE command is executed. Additionally to persisting the original, a phantom copy is persisted in Redis and set to expire 5 minutes after the original one. This is done to enable the Repository support to publish RedisKeyExpiredEvent holding the expired value via Springs ApplicationEventPublisher whenever a key expires even though the original values have already been gone. Expiry events will be received on all connected applications using Spring Data Redis repositories.

这篇关于从 redis 中删除键/值 - 幻键未删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆