Skip to content

redis - refactor: v6 client swap, API docs, and test uniformity - #2062

Open
jaredwray wants to merge 4 commits into
mainfrom
cursor/redis-v6-review-058b
Open

redis - refactor: v6 client swap, API docs, and test uniformity#2062
jaredwray wants to merge 4 commits into
mainfrom
cursor/redis-v6-review-058b

Conversation

@jaredwray

@jaredwray jaredwray commented Aug 30, 2026

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, refactor, docs, and tests from a v6 readiness pass on @keyv/redis.

The adapter already implements the v6 storage contract (capabilities.expires, absolute PXAT with PX fallback, cluster/sentinel). This PR closes the remaining gaps:

Fixes

  • Replacing client leaked listeners on the previous connection and kept a stale PXAT capability cache. Listeners are removed and PXAT is re-detected.
  • getMany and clear swallowed throwOnConnectError failures. They now share shouldRethrow() with the other batch methods.
  • connectionTimeout left a dangling timer after a successful connect.
  • createKeyv duplicated Keyv wiring and did not accept cluster/sentinel connect options. It now uses a shared KeyvRedisConnect type.

Adapter layout and jsDocs

  • Public properties sit under the constructor; public methods follow; private methods are last.
  • Public members document @param types and @returns.
  • Redis null replies from get / getMany / iterator map to undefined (never null).
  • Events go through Hookified (on / once / emit) and re-emit error, connect, disconnect, and reconnecting from the client.

Docs

  • README API lists properties, methods, helpers (createKeyv, createKeyvNonBlocking, defaultReconnectStrategy), and the Hookified event table.
  • v5 leftovers (useKeyPrefix, relative ttl on adapter set, createClient(url), PX 0, keyv.useUnlink) are gone.

Tests

  • test() with should … descriptions throughout.
  • Faker for keys and values.
  • Missing-key gets assert undefined and not.toBeNull().
  • Hookified wiring: once, client re-emit, no duplicate listeners, listener removal on client swap, PXAT reset.

Testing

Standalone Redis 7 (redis-server on localhost:6379): 12 files / 175 tests passed. Cluster and sentinel suites were not run in this environment (no Docker). Coverage on standalone is ~83% because cluster-only branches are unexercised; GitHub Actions should cover those.

Left as non-blocking (not in this PR): iterator() still throws regardless of throwOnErrors (reasonable for generators); Redis SCAN MATCH treats * in a namespace as a glob; @redis/client keyPrefix still should not be combined with adapter namespaces.

Open in Web Open in Cursor 

cursoragent and others added 2 commits August 30, 2026 23:53
Remove listeners from a replaced Redis client (matching Valkey), reset PXAT
detection on client swap, and rethrow connection errors from getMany and
clear so throwOnConnectError is consistent. Clear the connection-timeout
timer after a successful connect, strip namespace prefixes only from the
start of a key, and share a KeyvRedisConnect type so createKeyv accepts
cluster and sentinel options.

Co-authored-by: Jared Wray <me@jaredwray.com>
Document v5-to-v6 migration, absolute expires on set/setMany, the default
:: namespace separator, and createClient({ url }) instead of a URI string.

Co-authored-by: Jared Wray <me@jaredwray.com>
@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c9d78cc) to head (a73a43a).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #2062   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           55        55           
  Lines         5074      5086   +12     
  Branches       822       822           
=========================================
+ Hits          5074      5086   +12     

☔ 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.

cursoragent and others added 2 commits August 31, 2026 00:05
Order public properties under the constructor, keep private methods last, map Redis null to undefined, and document the Hookified event contract in the README.

Co-authored-by: Jared Wray <me@jaredwray.com>
Use test() throughout, faker for keys and values, cover Hookified event wiring, and assert missing gets return undefined rather than null.

Co-authored-by: Jared Wray <me@jaredwray.com>
@cursor cursor Bot changed the title redis - fix: Pre-v6 client swap, connect errors, and docs redis - refactor: v6 client swap, API docs, and test uniformity Aug 31, 2026
@jaredwray
jaredwray marked this pull request as ready for review August 31, 2026 00:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 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 Completed 2026-08-31T00:12:14.699393Z a73a43a Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a73a43adee

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

this.emit("error", error);
});
if (this._eventsWiredClient) {
this._eventsWiredClient.removeListener("error", this._errorHandler);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep errors handled on a replaced client

When client is replaced while the previous Redis connection is still open or connecting, removing its only error listener leaves that connection active and unguarded. A later socket error from the old client is therefore emitted as an unhandled Node.js error event and can terminate the process; either close the previous connection before detaching it or retain an error handler until its lifecycle ends.

Useful? React with 👍 / 👎.

Comment thread storage/redis/README.md

redisClient.on('end', () => {
console.log('Redis client disconnected');
`error`, `connect`, `disconnect`, and `reconnecting` are re-emitted on the adapter. Other Redis-client-only events (for example `ready`) can still be listened on `store.client`:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Map Redis end events to the advertised disconnect event

The newly documented disconnect subscription never fires for an actual node-redis disconnection: the Redis client signals connection termination with end (as the previous example in this README correctly used), while initClient() subscribes to a client event named disconnect. Users following this example will silently miss disconnect notifications, so the adapter should translate the client's end event or the documentation should not advertise this event.

Useful? React with 👍 / 👎.

*/
export function createKeyvNonBlocking(
connect?: string | RedisClientOptions | RedisClientType,
connect?: KeyvRedisConnect,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Disable retries on cluster and sentinel clients too

Expanding createKeyvNonBlocking to accept KeyvRedisConnect advertises cluster and sentinel support, but the implementation still casts every connection to RedisClientType and mutates standalone-only options.disableOfflineQueue and options.socket. Cluster and sentinel node settings live in their respective nested client defaults, so these assignments do not disable their offline queues or reconnect strategies; when Redis is unavailable, the supposedly non-blocking secondary cache can therefore continue queueing or retrying and delay requests.

Useful? React with 👍 / 👎.

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