Skip to content

[Messenger] Redis connection with prefix problem #60487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Qvinticom opened this issue May 20, 2025 · 0 comments
Open

[Messenger] Redis connection with prefix problem #60487

Qvinticom opened this issue May 20, 2025 · 0 comments

Comments

@Qvinticom
Copy link

Symfony version(s) affected

7.2

Description

When using a custom Redis adapter or client that automatically applies a key prefix (e.g. prefix:), streams are created under keys like prefix:. However, in Connection.php, the code that checks for and iterates over pending messages always uses the unprefixed $this->stream, so it never finds any messages.

Problematic code (around line 470 of Connection.php):

// Check for pending messages
if ($this->couldHavePendingMessages && empty($messages[$this->stream])) {
    $this->couldHavePendingMessages = false;
    // No pending, fetch new ones
    return $this->get();
}

// Iterate over messages in the stream
foreach ($messages[$this->stream] ?? [] as $key => $message) {
    …
}

Here, $this->stream is the bare stream name, but Redis actually stores messages under prefix:$this->stream, so $messages[$this->stream] is always empty and pending messages are never processed.

How to reproduce

  1. Configure Symfony Messenger with a Redis Stream transport using stream: 'my_stream'.
  2. Provide a custom \Redis instance (or wrapper) configured with a global key prefix, e.g. prefix:.
  3. Send messages to the transport.
  4. Run the worker (php bin/console messenger:consume).

Observed behavior:
The stream key in Redis is prefix:my_stream.
Connection::get() never finds any pending messages and always fetches new ones, skipping any existing entries.

Possible Solution

Use $this->redis->_prefix($this->stream) as the key when retrieving entries from $messages.

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants