-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Description
Laravel Version
12.30.1
PHP Version
8.4.2
Database Driver & Version
Redis 8.0.1
Description
I have a use case where I need to subscribe to a Redis event when a key expires, in order to trigger specific logic.
After enabling keyspace notifications in Redis with:
# redis-cli >
CONFIG SET notify-keyspace-events Ex
and subscribing with:
Redis::subscribe(['__keyevent@0__:expired'], function ($message) {
// handle logic
});
I don’t receive the global event.
This happens because Laravel only listens to channels with the prefix defined in config/database.php
under redis.options.prefix
.
If I replace the default prefix with an empty string, the subscription works correctly.
It looks like currently there is no way to listen to global Redis events without modifying the prefix.
Question
Is it possible to implement a way to subscribe to global events without having to remove/override the Redis prefix?
And also without having to set an empty prefix at runtime, since I might want to subscribe to both Redis global events and other prefixed channels at the same time.
This seems related to this issue: #29449
Steps To Reproduce
-
Enable Redis key expiration notifications:
CONFIG SET notify-keyspace-events Ex
-
Use Laravel to subscribe to the expiration channel:
Redis::subscribe(['__keyevent@0__:expired'], function ($message) { // handle logic });
-
Let a key expire.
-
Notice that no event is received unless you remove the prefix by setting
redis.options.prefix
to an empty string inconfig/database.php
.