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));
Answer from Abhijit Sarkar on Stack Overflow
🌐
Medium
subham-nitd.medium.com › using-redis-keyspace-notifications-for-discard-task-after-the-timeout-f42749e448f3
Using Redis Keyspace Notifications for Discard Task after the timeout | by SUBHAM MAJAVADIYA | Medium
August 10, 2020 - Subhams-MBP-2:~ subhammajavadiya$ redis-cli 127.0.0.1:6379> config set notify-keyspace-events Ex OK · By adding the below line in redis.conf and restarting the redis-server. ... would recommend enabling from redis.conf file in the production environment, to avoid the config reset if redis-server get restarted. To listen to the key expire event in spring boot application I have added spring.data.redis dependency in the build.gradleand implemented TaskTimeOutListener as MessageListener bean.
Discussions

Expired key trigger event - Spring data Redis - Stack Overflow
I am trying to setup a Key expiry event handler using spring data redis but am not able to make it work. I did some research but dint yeild expected results. Not sure what i am missing. I would lik... More on stackoverflow.com
🌐 stackoverflow.com
java - notify-keyspace-events in Redis - Stack Overflow
FYI when using ConfigureRedisAction.NO_OP you have to have configure Redis redis.conf file with config set notify-keyspace-events Egx. See Redis documentation and default implementation of ConfigureRedisAction at Spring session source code. More on stackoverflow.com
🌐 stackoverflow.com
Spring Session Redis web session expiration notifications not delayed until application is up again? - Stack Overflow
Is this indeed the current Spring Session Redis behavior ? Are there recommended solutions to "delay" the notifications ? ... As you mentioned, this is the standard behavior of Redis Keyspace notifications. More on stackoverflow.com
🌐 stackoverflow.com
google cloud platform - How to listen to keyspace events using Spring Data Redis with a GCP managed cluster? - Stack Overflow
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". More on stackoverflow.com
🌐 stackoverflow.com
June 30, 2022
People also ask

How to Enable keyspace notifications for Expired key Only?
IMPORTANT Keyspace notifications feature is available in Redis server version 2.8.0 or higher.By default keyspace, notifications are disabled in Redis to avoid unnecessary CPU utilization. There are two ways we can enable this either using redis-cli or redis.conf file.
🌐
engati.ai
engati.ai › blog › using-redis-keyspace-notifications-for-discard-task-after-the-timeout
How to discard tasks after timeouts with Redis keyspace notifications?
How to Enable Using Redis-CLI?
Subhams-MBP-2:~ subhammajavadiya$ redis-cli127.0.0.1:6379> config set notify-keyspace-events ExOK
🌐
engati.ai
engati.ai › blog › using-redis-keyspace-notifications-for-discard-task-after-the-timeout
How to discard tasks after timeouts with Redis keyspace notifications?
🌐
Medium
medium.com › spring-boot-world › listening-to-events-from-redis-in-your-spring-boot-application-62f89e76df89
Listening to Events From Redis in Your Spring Boot Application
February 22, 2026 - This feature allows you to listen to key-related events such as when keys are set, deleted, or expired. These notifications enable applications to trigger real-time business logic based on Redis events.
Find elsewhere
🌐
Engati
engati.ai › blog › using-redis-keyspace-notifications-for-discard-task-after-the-timeout
How to discard tasks after timeouts with Redis keyspace notifications? | Engati
By default keyspace, notifications are disabled in Redis to avoid unnecessary CPU utilization. There are two ways we can enable this either using redis-cli or redis.conf file. ... By adding the below line in redis.conf and restarting the ...
🌐
Redis
redis.io › docs › latest › develop › pubsub › keyspace-notifications
Redis keyspace notifications | Docs
1 day ago - Setting the parameter to the empty string disables notifications. In order to enable the feature a non-empty string is used, composed of multiple characters, where every character has a special meaning according to the following table: K Keyspace events, published with __keyspace@<db>__ prefix.
🌐
GitHub
github.com › azhar2407 › redis-keyspace-notification
GitHub - azhar2407/redis-keyspace-notification: This produces an pub sub example on how to make use redis keyspace notification to publish data based on redis key changes
This produces an example on how to make use of redis keyspace notification. To start the app: mvn spring-boot:run · There are 2 APIs I have exposed: add : localhost:8080/add?a=1&b=2 · evict: localhost:8080/evict?a=1 ·
Author   azhar2407
🌐
Programmer All
programmerall.com › article › 3996951028
[Redis] Spring boot uses redis' Keyspace Notifications to implement message notifications - Programmer All
You can find the corresponding description in redis.conf · # K Keyspace notification, with __keyspace@<db>__ is the prefix # E Key event notification, with __keysevent@<db>__ is the prefix # g del, expipre, rename and other types of unrelated general commands notification, ...
🌐
Titanwolf
blog.titanwolf.in › a
[Redis] Spring boot uses redis' Keyspace Notifications to implement message notifications - Titan Wolf
Omit the spring boot configuration, see github for the complete code. /** * The key expiration event is pushed to the topic with only the key but no value, because once it expires, the value does not exist. */ @Component public class JedisExpiredListener extends JedisPubSub { /** Refer to "EVENT NOTIFICATION" in redis.conf in the redis directory, redis default db{0, 15}, a total of 16 databases * K Keyspace events, published with __keyspace@<db>__ prefix.
🌐
Stack Overflow
stackoverflow.com › questions › 31114110 › what-are-the-notify-keyspace-events-in-redis
java - What are the notify-keyspace-events in Redis - Stack Overflow
May 23, 2017 - In other words, it's really not implemented like what Redis describes at https://redis.io/docs/manual/keyspace-notifications/ ... Have you posted your sample code (project) any where? I am struck on a implementation same as this logic. 2023-11-07T06:41:17.403Z+00:00 ... Example code that I used and the feature request to allow the selection of which type of events to receive: github.com/spring-projects/spring-data-redis/issues/2757 2023-11-09T02:05:11.85Z+00:00
🌐
Dragonfly
dragonflydb.io › error-solutions › unable-to-configure-redis-to-keyspace-notifications
[Solved] unable to configure redis to keyspace notifications
Make sure that the notify-keyspace-events option is enabled in your Redis configuration file. You can do this by opening the configuration file and checking that the notify-keyspace-events option is uncommented and set to the appropriate value.