feat(redis): support setItems (#705)#782
Conversation
The redis driver already implements getItems via MSET's counterpart MGET; this adds the symmetric setItems. It uses a single MSET when no TTL applies, and falls back to a pipeline of SET ... EX (mirroring setItem) when a TTL is set per-item or via commonOptions/opts, since MSET cannot set a per-key TTL.
📝 WalkthroughWalkthroughThis PR adds ChangesRedis setItems Feature
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 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)
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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/drivers/redis.test.ts`:
- Around line 43-59: Update the test "setItems with ttl sets each key with an
expiry" to assert TTL for every key in the batch: after calling
ctx.storage.setItems(...) and creating the ioredisMock client
(ioredisMock.default(...)), verify both values with client.get("test:s6:a") and
client.get("test:s6:b") and assert client.ttl("test:s6:a") and
client.ttl("test:s6:b") are > 0; keep using ctx.storage.setItems and
client.disconnect as currently used.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a20272a8-97cc-43b6-a743-1a25f1230917
📒 Files selected for processing (2)
src/drivers/redis.tstest/drivers/redis.test.ts
| it("setItems with ttl sets each key with an expiry", async () => { | ||
| await ctx.storage.setItems( | ||
| [ | ||
| { key: "s6:a", value: "a" }, | ||
| { key: "s6:b", value: "b" }, | ||
| ], | ||
| { ttl: 1000 }, | ||
| ); | ||
|
|
||
| const client = new (ioredisMock as any).default("ioredis://localhost:6379/0"); | ||
|
|
||
| expect(await client.get("test:s6:a")).toBe("a"); | ||
| expect(await client.get("test:s6:b")).toBe("b"); | ||
| expect(await client.ttl("test:s6:a")).toBeGreaterThan(0); | ||
|
|
||
| await client.disconnect(); | ||
| }); |
There was a problem hiding this comment.
Verify TTL for all keys, not just the first.
The test asserts TTL for "test:s6:a" (line 56) but not for "test:s6:b", even though the test name promises "sets each key with an expiry." If the implementation inadvertently applied TTL only to the first key in the batch, this test would not detect the bug.
🧪 Proposed fix to verify both keys
expect(await client.get("test:s6:a")).toBe("a");
expect(await client.get("test:s6:b")).toBe("b");
expect(await client.ttl("test:s6:a")).toBeGreaterThan(0);
+expect(await client.ttl("test:s6:b")).toBeGreaterThan(0);
await client.disconnect();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it("setItems with ttl sets each key with an expiry", async () => { | |
| await ctx.storage.setItems( | |
| [ | |
| { key: "s6:a", value: "a" }, | |
| { key: "s6:b", value: "b" }, | |
| ], | |
| { ttl: 1000 }, | |
| ); | |
| const client = new (ioredisMock as any).default("ioredis://localhost:6379/0"); | |
| expect(await client.get("test:s6:a")).toBe("a"); | |
| expect(await client.get("test:s6:b")).toBe("b"); | |
| expect(await client.ttl("test:s6:a")).toBeGreaterThan(0); | |
| await client.disconnect(); | |
| }); | |
| it("setItems with ttl sets each key with an expiry", async () => { | |
| await ctx.storage.setItems( | |
| [ | |
| { key: "s6:a", value: "a" }, | |
| { key: "s6:b", value: "b" }, | |
| ], | |
| { ttl: 1000 }, | |
| ); | |
| const client = new (ioredisMock as any).default("ioredis://localhost:6379/0"); | |
| expect(await client.get("test:s6:a")).toBe("a"); | |
| expect(await client.get("test:s6:b")).toBe("b"); | |
| expect(await client.ttl("test:s6:a")).toBeGreaterThan(0); | |
| expect(await client.ttl("test:s6:b")).toBeGreaterThan(0); | |
| await client.disconnect(); | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@test/drivers/redis.test.ts` around lines 43 - 59, Update the test "setItems
with ttl sets each key with an expiry" to assert TTL for every key in the batch:
after calling ctx.storage.setItems(...) and creating the ioredisMock client
(ioredisMock.default(...)), verify both values with client.get("test:s6:a") and
client.get("test:s6:b") and assert client.ttl("test:s6:a") and
client.ttl("test:s6:b") are > 0; keep using ctx.storage.setItems and
client.disconnect as currently used.
Closes #705.
The redis driver already implements
getItems(viaMGET), so this adds the symmetricsetItems:MSET(efficient bulk write).options.ttl,commonOptions.ttl, or the driver'sopts.ttl) → a pipeline ofSET ... EX, mirroringsetItem, sinceMSETcannot set a per-key TTL.Covered by the shared driver
setItemstest (theMSETpath) plus a redis-specific test for the TTL/pipeline path.Summary by CodeRabbit