Skip to content

Unable to register KeyspaceEventMessageListener in GCP MemoryStore instances #3151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nandorholozsnyak opened this issue May 15, 2025 · 1 comment
Labels
status: duplicate A duplicate of another issue

Comments

@nandorholozsnyak
Copy link

nandorholozsnyak commented May 15, 2025

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 15, 2025
@mp911de
Copy link
Member

mp911de commented May 19, 2025

Duplicate of #2894

Please disable Spring Data Redis Keyspace notification configuration (ideally through the annotation) and configure your server upfront.

@mp911de mp911de closed this as completed May 19, 2025
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants