Skip to content

redis - fix: clear() and iterator() match the namespace literally - #2185

Merged
jaredwray merged 1 commit into
mainfrom
claude/dreamy-ramanujan-5sjbg9
Oct 3, 2026
Merged

jaredwray merged 1 commit into
mainfrom
claude/dreamy-ramanujan-5sjbg9

Conversation

@jaredwray

Copy link
Copy Markdown
Owner

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Bug fix, with docs.

clear() and iterator() built their SCAN MATCH pattern as <namespace><keyPrefixSeparator>* without escaping it, so *, ?, [, ] and \ in the namespace or separator were read as glob syntax:

  • clear() on namespace tenant* (likewise user? or t[12]) deleted another namespace's keys, and iterator() returned them.
  • A namespace such as t[12] or a\b never matched its own keys, so clear() left them behind.

v5 (@keyv/redis@5.1.6) built the same pattern. @keyv/valkey fixed the same bug in jaredwray/keyv#2147.

Changes

  • getKeyPattern() escapes those characters in the namespace and separator, as @keyv/valkey does.
  • filterScannedKeys() also checks each SCAN result against the literal prefix, so clear() can't delete another namespace's keys whatever glob syntax the server supports. It also holds the existing no-namespace filtering, which clear() and iterator() now share.
  • Regression tests for clear() and iterator() with glob characters in the namespace, and for a separator with glob characters. All three fail on main and pass here.
  • README: documents the literal matching, and that a namespace extending another with the separator (my-namespace::archive under my-namespace) is still covered by it, as the Valkey README does.
  • Migration guide and keyv-migrate skill references: a @keyv/redis section and updated wording, since v5 behaved differently (per AGENTS.md).

Verification

  • pnpm test in storage/redis against local Redis (standalone, TLS, a 3-node cluster and sentinel): lint clean, 14 files and 257 tests pass, and every branch in the changed code is covered.
  • pnpm --filter @keyv/website test (skill and docs validation): 32 tests pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Wm1wtCGzQJEyYZdekgNVge


Generated by Claude Code

clear() and iterator() passed `<namespace><keyPrefixSeparator>*` to
SCAN MATCH without escaping it, so `*`, `?`, `[`, `]` and `\` in the
namespace or separator were read as glob syntax. clear() on namespace
`tenant*` deleted namespace `tenant-prod`'s keys and iterator() returned
them, while a namespace such as `t[12]` or `a\b` never matched its own
keys. v5 built the same pattern.

Both now build the pattern through getKeyPattern(), which escapes those
characters in the namespace and separator, as @keyv/valkey does since
#2147. filterScannedKeys() also checks each SCAN result
against the literal prefix, so clear() can't delete another namespace's
keys whatever glob syntax the server supports.

Adds regression tests for clear(), iterator() and a separator with glob
characters, documents the literal matching and the separator limitation
in the README, and notes the change in the v5-to-v6 migration guide and
the keyv-migrate skill references.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wm1wtCGzQJEyYZdekgNVge
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 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 ✅ Completed 2026-10-03T22:28:26.654368Z 752e89c 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.

@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6361ae1) to head (752e89c).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #2185   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           56        56           
  Lines         5790      5797    +7     
  Branches       996       987    -9     
=========================================
+ Hits          5790      5797    +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jaredwray
jaredwray merged commit b91b8bf into main Oct 3, 2026
16 checks passed
@jaredwray
jaredwray deleted the claude/dreamy-ramanujan-5sjbg9 branch October 3, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants