Description
Based on the docs when devs are using @RedisHash
based solutions and when those types are having @Indexed
fields, those set records are not going to be expired even the hash expires.
To overcome this issue the docs says a keyspace event listener must be enabled/registered. I tried this way on a GCP MemoryStore instance but it does fail with the following:
RedisCommandExecutionException: ERR unknown command 'CONFIG', with args beginning with: 'GET' 'notify-keyspace-events'
Spring Data Redis version: 3.4.5
The app is annotated with the following settings:
@EnableRedisRepositories(enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_DEMAND)
Because of the ON_DEMAND setting the exception comes on the very first "insert" into Redis, it does fail but after that I don't see more of these, but as we know it does not register the required listener.
The problem is that GCP MemoryStore instances do not permit the CONFIG parameter usage, even for reading it, I did disable overriding it, but that is a second step and the registration fails in the first one.
What can I do?
- Right now I have to disable it and wait for a potential fix in the lib.
What can be the fix?
I'm not fully sure, but I may make the listener registration fault tolerant, by catching the exception when reading the config parameter. Here is the original implementation:
org.springframework.data.redis.listener.KeyspaceEventMessageListener#init
public void init() {
RedisConnectionFactory connectionFactory = listenerContainer.getConnectionFactory();
if (StringUtils.hasText(keyspaceNotificationsConfigParameter) && connectionFactory != null) {
try (RedisConnection connection = connectionFactory.getConnection()) {
RedisServerCommands commands = connection.serverCommands();
Properties config = commands.getConfig("notify-keyspace-events");
if (!StringUtils.hasText(config.getProperty("notify-keyspace-events"))) {
commands.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter);
}
}
}
doRegister(listenerContainer);
}
It override the notify-keyspace-events
config parameter if it is set, so in my opinion we can catch an exception here.
The question if the event listener will work if we cannot set the config parameter to Ex
as the default implementation would do that.
Based on this list its value by default is empty, but it should be configurable from outside.