PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 5, 2022

[FIXED] How to listen to keyspace events using Spring Data Redis with a GCP managed cluster?

 September 05, 2022     google-cloud-platform, redis, spring, spring-data-redis     No comments   

Issue

I am using secondary indexes with Redis thanks to Spring Data Redis @Indexed annotations. My entry has a TTL. This has a side effect of keeping the indexes after the expiration of the main entry. This is expected, and Spring can listen to keyspace expiry events to remove those indexes once the main TTL is done.

However, enabling the listening to keyspace expiry events with Spring, I face the following error at startup:

ERR unknown command 'CONFIG'

This is how I configured the listener:

@EnableRedisRepositories(enableKeyspaceEvents = EnableKeyspaceEvents.ON_STARTUP)

What can I do to make this work?


Solution

This problem is linked to the fact that the Redis cluster is managed, and as such remote clients can't call CONFIG on it. When enabling the Spring keyspace event listener, it tries to configure Redis to emit keyspace expiry events, by setting the notify-keyspace-events config key to "Ex".

The workaround to this is:

  1. Configure your MemoryStore on GCP, adding the notify-keyspace-events key with "Ex" as value.
  2. Use @EnableRedisRepositories(enableKeyspaceEvents = EnableKeyspaceEvents.ON_STARTUP, keyspaceNotificationsConfigParameter = "") for your client configuration. The explicitely empty String prevents Spring from trying to override the remote configuration.


Answered By - Docteur
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing