feat(redis): add clientInfoTag support with version detection#736
feat(redis): add clientInfoTag support with version detection#736vchomakov wants to merge 9 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds an optional Changes
Sequence Diagram(s)sequenceDiagram
participant App as "App"
participant Driver as "RedisDriver"
participant PKG as "package.json"
participant IoRedis as "ioredis"
participant Redis as "Redis"
App->>Driver: create driver(opts)
alt opts.clientInfoTag provided
Driver->>IoRedis: init(clientInfoTag = opts.clientInfoTag)
else clientInfoTag omitted
Driver->>PKG: read version
PKG-->>Driver: version or missing
Driver->>IoRedis: init(clientInfoTag = "unstorage" or "unstorage_vX.X.X")
end
IoRedis->>Redis: CLIENT SETINFO LIB-NAME ioredis(<clientInfoTag>)
Redis-->>IoRedis: OK
IoRedis-->>Driver: connection established
Driver-->>App: driver instance
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/drivers/redis.ts`:
- Around line 58-60: The getDefaultClientInfoTag function currently assumes
pkg.version exists; update getDefaultClientInfoTag to guard against
missing/empty pkg.version (from the package import) and return the fallback
string "unstorage" when version is falsy, otherwise return the current
`unstorage_v${pkg.version}` tag; locate and modify the getDefaultClientInfoTag
function and the use of pkg.version to perform a truthy check (e.g., if
(!pkg.version) return "unstorage") before constructing the versioned tag.
- Around line 62-63: The file incorrectly wraps the driver declaration with an
undefined defineDriver(...) and creates duplicate default exports; remove the
defineDriver(...) wrapper so the top-level const driver:
DriverFactory<RedisOptions, Redis | Cluster> = (opts) => { ... } stands alone,
ensure there is only a single default export (leave export default driver; at
the bottom), and delete the extraneous export/default around defineDriver and
any other duplicate export statements referencing driver or defineDriver.
In `@test/drivers/redis.test.ts`:
- Around line 41-42: The test is referencing an undefined variable `driver`;
change the lookup to use the TestContext's driver (ctx.driver) instead: call
ctx.driver.getInstance?.() to obtain the instance and read (instance?.options as
any)?.clientInfoTag from that instance; also ensure any use of `binaryDriver` in
this scope is replaced with the appropriate ctx.driver or removed if not
available. Locate occurrences around getInstance and clientInfoTag in the test
callback and update them to use ctx.driver so the TestContext-provided driver is
used consistently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e8e500b4-58a1-482a-8b14-a6aff2bbb4c6
📒 Files selected for processing (3)
docs/2.drivers/redis.mdsrc/drivers/redis.tstest/drivers/redis.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/drivers/redis.test.ts (1)
40-45: Strengthen these tests around the actual default and cluster paths.Line 44 still allows the
"unstorage"fallback even though this repo should produce a versioned tag, and both tests only exercise the standalonenew Redis(...)branch. A brokenpackage.jsonimport or a regression inclusterOptions.redisOptions.clientInfoTagwould still pass.🧪 Tighten the standalone assertion
- // Should be either "unstorage_vX.X.X" or "unstorage" (fallback) - expect(tag).toMatch(/^unstorage(_v[\d.]+.*)?$/); + expect(tag).toMatch(/^unstorage_v[\d.]+.*$/);Please add a separate cluster-mode assertion as well.
Also applies to: 47-55
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/drivers/redis.test.ts` around lines 40 - 45, Tighten the tests to assert the actual versioned clientInfoTag and add a cluster-mode assertion: update the standalone test that reads instance = ctx.driver.getInstance?.() / tag = (instance?.options as any)?.clientInfoTag to require the versioned form (e.g., matching /^unstorage_v[\d.]+/) instead of allowing the "unstorage" fallback, and add a new assertion that constructs/uses the cluster path (inspect clusterOptions.redisOptions.clientInfoTag or create a cluster instance) and asserts its clientInfoTag also matches the versioned pattern; target the existing symbols ctx.driver.getInstance, new Redis(...) code path, and clusterOptions.redisOptions.clientInfoTag when adding the additional test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/drivers/redis.ts`:
- Around line 79-84: The clusterOptions construction currently lets
options.clusterOptions.redisOptions overwrite the top-level clientInfoTag;
change the merge so the top-level clientInfoTag is authoritative (e.g., spread
options.clusterOptions?.redisOptions first and then set clientInfoTag, or
Object.assign with clientInfoTag last) so that clientInfoTag from options always
overrides any nested value when building clusterOptions.redisOptions.
---
Nitpick comments:
In `@test/drivers/redis.test.ts`:
- Around line 40-45: Tighten the tests to assert the actual versioned
clientInfoTag and add a cluster-mode assertion: update the standalone test that
reads instance = ctx.driver.getInstance?.() / tag = (instance?.options as
any)?.clientInfoTag to require the versioned form (e.g., matching
/^unstorage_v[\d.]+/) instead of allowing the "unstorage" fallback, and add a
new assertion that constructs/uses the cluster path (inspect
clusterOptions.redisOptions.clientInfoTag or create a cluster instance) and
asserts its clientInfoTag also matches the versioned pattern; target the
existing symbols ctx.driver.getInstance, new Redis(...) code path, and
clusterOptions.redisOptions.clientInfoTag when adding the additional test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3d70b523-109f-424d-a299-bc2c4420664b
📒 Files selected for processing (2)
src/drivers/redis.tstest/drivers/redis.test.ts
|
Dear @pi0 , I would appreciate a review of this change. Thanks! |
Resolves #735
Description
Adds
clientInfoTagsupport to the Redis driver to leverage Redis'sCLIENT SETINFOcommand.This feature helps Redis administrators identify which higher-level library is using ioredis by setting a custom tag in the
CLIENT SETINFO LIB-NAMEcommand.Changes
clientInfoTagoption toRedisOptionsinterfaceunstorage_vX.X.Xusing package.json versionclientInfoTagoverrideclusterOptions.redisOptionsclientInfoTagbehaviorExample Usage
Testing
All existing tests pass (19/19)
Added 2 new tests for clientInfoTag functionality
Build successful
Linter passes
Type checking passes
References
Redis CLIENT SETINFO documentation: https://redis.io/docs/latest/commands/client-setinfo/
ioredis clientInfoTag option: https://github.com/redis/ioredis#client-setinfo
Summary by CodeRabbit
New Features
Tests