Redis-过期索引未删除

问题描述 投票:0回答:1

我发现以下有关Redis中索引到期的问题(Spring Redis - Indexes not deleted after main entry expires

问题是主要条目和:phantom条目已过期并且已被正确删除,但是相应的:idx条目在Redis中成为孤立对象。

提议的解决方案之一是启用KeyspaceEvents,以便Redis在清理作业期间自动删除过期条目的索引。

[不幸的是,此解决方案不适用于我们的Spring Boot应用程序,因为我们将Redis Enterprise用作云环境中提供的服务,这不允许我们进行任何配置更改(CONFIG命令被禁用)。

我在这里尝试过:

@Configuration
@EnableRedisRepositories(enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP)
public class RedisConfiguration {...}

编辑:我以为这对我的本地Redis docker镜像有效,但是我错了!在我们提供的Redis(Enterprise)服务上,甚至无法通过以下消息进行设置:Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'CONFIG'...

有人可以提示我如何删除索引吗?

我们目前没有很多:idx条目,但是必须/应该将它们与:phantom条目一起删除,以避免保留任何“孤立”条目。

提前感谢。

java spring-boot redis spring-data-redis
1个回答
2
投票

我可以找到删除键:phantom:idx的解决方案。

在Redis配置类中,应放置以下内容:

@Configuration
@EnableRedisRepositories(enableKeyspaceEvents = EnableKeyspaceEvents.ON_STARTUP, basePackages = {
    "com.aaaaa.bbbbb.persistence.model.repository" }, keyspaceNotificationsConfigParameter = "")

当您将“ keyspaceNotificationsConfigParameter”属性设置为空字符串时,将不会执行在AWS Redis中不起作用的CONFIG命令,但会实例化到期事件侦听器。

此属性带来一个默认值(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);
}

如何不满足此条件

if (StringUtils.hasText(keyspaceNotificationsConfigParameter)) {

未执行CONFIG命令。

我认为Spring应该基于设置带有空字符串的属性来改善这一点,而不是那样做。

[唯一需要的是,在AWS ElastiCache(Redis)中,将一个值设置为“ notify-keyspace-events”参数,例如AKE,这意味着将通知所有事件。

© www.soinside.com 2019 - 2024. All rights reserved.