Nan*_*Sil 1 java redis spring-data-redis spring-boot
我发现了以下关于Redis 中索引过期问题的问题(Spring Redis - 主条目过期后未删除索引)。
问题是 main 和:phantom条目过期并被正确删除,但相应的:idx条目在 Redis 中孤立存在。
提议的解决方案之一是启用 KeyspaceEvents,以便 Redis 在清理作业期间自动删除过期条目的索引。
不幸的是,这个解决方案不适用于我们的 Spring Boot 应用程序,因为我们在云环境中使用 Redis Enterprise 作为提供的服务,这不允许我们进行任何配置更改(CONFIG命令被禁用)。
这是我尝试过的:
@Configuration
@EnableRedisRepositories(enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP)
public class RedisConfiguration {...}
Run Code Online (Sandbox Code Playgroud)
编辑:
我认为这适用于我本地的 Redis docker 映像,但我错了!在我们提供的 Redis (Enterprise) 服务上,甚至无法使用以下消息进行设置:
Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'CONFIG'...
谁能给我一个关于如何删除索引的提示?
我们目前没有很多:idx条目,但它们必须/应该与:phantom条目一起删除,以避免保留任何“孤立”条目。
提前致谢。
我可以找到删除键:phantom和:idx的解决方案。
在Redis配置类中,应该放置以下内容:
@Configuration
@EnableRedisRepositories(enableKeyspaceEvents = EnableKeyspaceEvents.ON_STARTUP, basePackages = {
"com.aaaaa.bbbbb.persistence.model.repository" }, keyspaceNotificationsConfigParameter = "")
Run Code Online (Sandbox Code Playgroud)
当您将“keyspaceNotificationsConfigParameter”属性设置为空字符串时,不会执行在AWS Redis 中不起作用的CONFIG 命令,但通过这种方式实例化了Expiration Event Listener。
此属性带来一个默认值 (Ex),它会导致执行 CONFIG 命令。
这是由以下弹簧代码发生的:
public void init() {
if (StringUtils.hasText(keyspaceNotificationsConfigParameter)) {
RedisConnection connection = listenerContainer.getConnectionFactory().getConnection();
try {
Properties config = connection.getConfig("notify-keyspace-events");
if (!StringUtils.hasText(config.getProperty("notify-keyspace-events"))) {
connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter);
}
} finally {
connection.close();
}
}
doRegister(listenerContainer);
}
Run Code Online (Sandbox Code Playgroud)
怎么不满足这个条件
if (StringUtils.hasText(keyspaceNotificationsConfigParameter)) {
Run Code Online (Sandbox Code Playgroud)
不执行 CONFIG 命令。
我认为 Spring 应该基于设置一个空字符串的属性来改进这一点,而不是让它流动。
唯一还需要的是,在 AWS ElastiCache (Redis) 中,为“notify-keyspace-events”参数设置了一个值,例如 AKE,这意味着将通知所有事件。
| 归档时间: |
|
| 查看次数: |
1405 次 |
| 最近记录: |