Abhijit Sarkar
Abhijit Sarkar

Reputation: 24528

How to Enable Keyspace Notifications for Expired Keys using Spring Data Redis

Is there a way to run the following command from Spring Data Redis, possibly using RedisTemplate?

$ redis-cli config set notify-keyspace-events Ex

My understanding is RedisTemplate can run lua scripts, can the above be converted to one?

Upvotes: 0

Views: 2610

Answers (1)

Abhijit Sarkar
Abhijit Sarkar

Reputation: 24528

Answering my own question, turns out there's no need to run lua script:

If using non-reactive Redis connection:

RedisConnection conn = null;
try {
    conn = connectionFactory.getConnection();
    conn.setConfig("notify-keyspace-events", "Ex");
} finally {
    if (conn != null) {
        conn.close();
    }
}

If using reactive Redis connection:

ReactiveRedisConnection conn = connectionFactory.getReactiveConnection();
        conn
                .serverCommands()
                .setConfig("notify-keyspace-events", "Ex")
                .filter(status -> status.equals("OK"))
                .doFinally(unused -> conn.close())
                .block(Duration.ofSeconds(5L));

Upvotes: 1

Related Questions