Skip to content

Fix empty keys in keyspace notifications - #4549

Merged
petyaslavova merged 3 commits into
redis:masterfrom
BlueX888:contrib/keyspace-empty-key
Nov 2, 2026
Merged

petyaslavova merged 3 commits into
redis:masterfrom
BlueX888:contrib/keyspace-empty-key

Conversation

@BlueX888

@BlueX888 BlueX888 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Problem

KeyNotification.try_parse drops keyspace notifications for empty keys: the _KEYSPACE_PATTERN and _SUBKEYSPACE_PATTERN regexes use (.+) for the key, so a channel like __keyspace@0__: — a zero-length key, which is valid in Redis (e.g. SET "" value) — fails to parse and try_parse returns None.

Change

Allow an empty key in the two keyspace patterns ((.+) -> (.*)). The keyevent patterns keep (.+): Redis event names are never empty. Nothing else in the parsing changes.

Testing

  • New parametrized regression test_empty_keyspace_key (str and bytes, keyspace and subkeyspace channels): an empty key parses, key == "", subkeys and is_keyspace as expected.
  • All existing tests in tests/test_keyspace_notifications.py pass, including the trailing-newline and key-prefix cases the re.DOTALL comment guards.
  • Full suite (fixed_client, standalone, cluster) run locally against Redis 8.10.3 with zero candidate-caused failures — verified against an identical base run in the same window, with the handful of differing failures re-confirmed as timing-flaky on both sides.

Note

Low Risk
Narrow regex change in notification parsing with targeted regression tests; no auth, I/O, or broader API behavior changes.

Overview
KeyNotification.try_parse previously returned None for channels whose Redis key is empty (e.g. __keyspace@0__: after SET "" value), because _KEYSPACE_PATTERN and _SUBKEYSPACE_PATTERN required at least one character with (.+).

Those two patterns now use (.*) so a zero-length key parses as key == "". Keyevent-style patterns are unchanged ((.+)), since event names are never empty.

Adds parametrized test_empty_keyspace_key (str/bytes, keyspace and subkeyspace) to lock in empty-key parsing and subkey handling.

Reviewed by Cursor Bugbot for commit 59c0d6c. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-31T18:54:35.498654Z
We couldn’t complete this review. Comment @codex review to try again.
2d65a43 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@petyaslavova petyaslavova left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @BlueX888, thank you for your contribution!

Confirmed: the keyspace and subkeyspace patterns were the only notification forms that dropped empty keys, and the new test covers both. LGTM once CI is green.

@petyaslavova petyaslavova added the maintenance Maintenance (CI, Releases, etc) label Nov 2, 2026
@petyaslavova
petyaslavova merged commit 428f0b5 into redis:master Nov 2, 2026
132 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Maintenance (CI, Releases, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants