Redis - 过期索引不会被删除 [英] Redis - Expired Indexes are not deleted

查看:116
本文介绍了Redis - 过期索引不会被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了以下问题(Spring Redis - Indexes not主条目过期后删除)关于Redis中索引过期的问题.

I found the following question (Spring Redis - Indexes not deleted after main entry expires) about a problem with expiration of indexes in Redis.

问题是 main 和 :phantom 条目过期并被正确删除,但相应的 :idx 条目在 Redis 中孤立存在.

The problem is that the main and :phantom entries expire and are being deleted correctly, but the corresponding :idx entries survive orphaned in Redis.

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

One of the proposed solutions was to enable KeyspaceEvents, so that Redis automatically removes indexes of expired entries during the cleanup job.

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

Unfortunately this solution will not work for our Spring Boot application, as we are using Redis Enterprise as a provided service inside a cloud environment, which does not allow us to make any configuration changes (CONFIG command is disabled).

这是我尝试过的:

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


我以为这适用于我本地的 Redis docker 映像,但我错了!在我们提供的 Redis(企业)服务上,甚至无法使用以下消息进行设置:
Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'CONFIG'...

谁能给我一个关于如何删除索引的提示?

Can anybody give me a hint on how to get the indexes deleted?

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

We currently do not have many :idx entries, but they must/should be deleted together with the :phantom entry, to avoid keeping any 'orphaned' entries.

提前致谢.

推荐答案

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

I could find the solution to delete the keys :phantom and :idx.

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

In the Redis configuration class, the following should be put:

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

当您将keyspaceNotificationsConfigParameter"属性设置为空字符串时,不会执行在AWS Redis中不起作用的CONFIG命令,而是通过这种方式实例化了Expiration Event Listener.

When you set the "keyspaceNotificationsConfigParameter" attribute to the empty string, the CONFIG command that does not work in AWS Redis is not executed, but in this way, the Expiration Event Listener is instantiated.

该属性带来一个默认值(Ex),它会导致执行 CONFIG 命令.

This attribute brings a default value (Ex), which causes the CONFIG command to be executed.

这是由以下弹簧代码发生的:

This happens by the following spring code:

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 命令未执行.

the CONFIG command is not executed.

我认为 Spring 应该改进这一点,而不是根据使用空字符串设置属性的方式进行改进.

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

The only thing that is also needed is that in the AWS ElastiCache (Redis) a value is set to the "notify-keyspace-events" parameter, such as AKE, which means that all events will be notified.

这篇关于Redis - 过期索引不会被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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