Skip to content

Unable to subscribe to Redis global key expiration events due to Laravel prefix handling #57161

@Lukasss93

Description

@Lukasss93

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

  1. Enable Redis key expiration notifications:

    CONFIG SET notify-keyspace-events Ex
  2. Use Laravel to subscribe to the expiration channel:

    Redis::subscribe(['__keyevent@0__:expired'], function ($message) {
        // handle logic
    });
  3. Let a key expire.

  4. Notice that no event is received unless you remove the prefix by setting redis.options.prefix to an empty string in config/database.php.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions