Skip to content

Commit 8b3b33c

Browse files
committed
refactor: tighten READ_COMMANDS and clarify auto-pipeline test names
Make READ_COMMANDS module-private, add touch as a read command, drop fcallRo, and rewrite auto-pipeline.test.ts test descriptions to reflect the read/write pipeline-splitting behavior they actually verify.
1 parent 71a247e commit 8b3b33c

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

packages/redis/pkg/auto-pipeline.test.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const getExecutor = (redis: Redis): AutoPipelineExecutorLike =>
2424
(redis as unknown as { autoPipelineExecutor: AutoPipelineExecutorLike }).autoPipelineExecutor;
2525

2626
describe("Auto pipeline", () => {
27-
test("should execute all commands inside a Promise.all in a single pipeline", async () => {
27+
test("should batch a large Promise.all of mixed reads and writes into one read and one write pipeline", async () => {
2828
const persistentKey = newKey();
2929
const persistentKey2 = newKey();
3030
const persistentKey3 = newKey();
@@ -177,7 +177,7 @@ describe("Auto pipeline", () => {
177177
expect(redis.pipelineCounter).toBe(2);
178178
});
179179

180-
test("should group async requests with sync requests", async () => {
180+
test("should group fire-and-forget writes with the next awaited write into one write pipeline, then reads into a separate read pipeline", async () => {
181181
const redis = Redis.fromEnv({
182182
latencyLogging: false,
183183
enableAutoPipelining: true,
@@ -209,7 +209,7 @@ describe("Auto pipeline", () => {
209209
expect(redis.pipelineCounter).toBe(2);
210210
});
211211

212-
test("should execute a pipeline for each consecutive awaited command", async () => {
212+
test("should create a new pipeline for each consecutively awaited command", async () => {
213213
const redis = Redis.fromEnv({
214214
latencyLogging: false,
215215
enableAutoPipelining: true,
@@ -238,7 +238,7 @@ describe("Auto pipeline", () => {
238238
expect([res1, res2, res3]).toEqual([1, 2, "OK"]);
239239
});
240240

241-
test("should execute a single pipeline for several commands inside Promise.all", async () => {
241+
test("should batch writes inside Promise.all into a single write pipeline while skipping excluded commands like dbsize", async () => {
242242
const redis = Redis.fromEnv({
243243
latencyLogging: false,
244244
enableAutoPipelining: true,
@@ -268,7 +268,7 @@ describe("Auto pipeline", () => {
268268
expect(redis.pipelineCounter).toBe(2);
269269
});
270270

271-
test("should be able to utilize only redis functions 'use' like usual", async () => {
271+
test("should still apply redis.use middleware to auto-pipelined commands", async () => {
272272
const redis = Redis.fromEnv({
273273
latencyLogging: false,
274274
enableAutoPipelining: true,
@@ -293,7 +293,7 @@ describe("Auto pipeline", () => {
293293
expect(redis.pipelineCounter).toBe(1);
294294
});
295295

296-
test("should be able to utilize only redis functions 'multi' and 'pipeline' like usual", async () => {
296+
test("should not increment the auto-pipeline counter when explicit pipeline() or multi() is used", async () => {
297297
const redis = Redis.fromEnv({
298298
latencyLogging: false,
299299
enableAutoPipelining: true,
@@ -320,7 +320,7 @@ describe("Auto pipeline", () => {
320320
expect(redis.pipelineCounter).toBe(0);
321321
});
322322

323-
test("should be able to utilize only redis functions 'createScript' like usual", async () => {
323+
test("should auto-pipeline createScript().eval() calls", async () => {
324324
const redis = Redis.fromEnv({
325325
latencyLogging: false,
326326
enableAutoPipelining: true,
@@ -340,7 +340,7 @@ describe("Auto pipeline", () => {
340340
expect(redis.pipelineCounter).toBe(1);
341341
});
342342

343-
test("should handle JSON commands correctly", async () => {
343+
test("should split JSON reads and writes into separate pipelines across awaited Promise.all calls", async () => {
344344
const redis = Redis.fromEnv({
345345
latencyLogging: false,
346346
enableAutoPipelining: true,
@@ -376,7 +376,7 @@ describe("Auto pipeline", () => {
376376
expect(redis.pipelineCounter).toBe(4);
377377
});
378378

379-
test("should throw errors granularly", async () => {
379+
test("should isolate errors between parallel callers so a caught failure doesn't affect another concurrent flow", async () => {
380380
// in this test, we have two methods being called parallel. both
381381
// use redis, but one of them has try/catch. when the request in
382382
// try fails, it shouldn't make the request in the parallel request
@@ -422,7 +422,7 @@ describe("Auto pipeline", () => {
422422
});
423423

424424
describe("max pipeline size", () => {
425-
test("should split into multiple pipelines when exceeding max size", async () => {
425+
test("should split into two pipelines when MAX_PIPELINE_SIZE + 500 commands are queued", async () => {
426426
const redis = Redis.fromEnv({
427427
latencyLogging: false,
428428
enableAutoPipelining: true,
@@ -445,7 +445,7 @@ describe("Auto pipeline", () => {
445445
expect(redis.pipelineCounter).toBe(2);
446446
});
447447

448-
test("should use exactly one pipeline when at max size", async () => {
448+
test("should use exactly one pipeline when the queued command count equals MAX_PIPELINE_SIZE", async () => {
449449
const redis = Redis.fromEnv({
450450
latencyLogging: false,
451451
enableAutoPipelining: true,
@@ -466,7 +466,7 @@ describe("Auto pipeline", () => {
466466
expect(redis.pipelineCounter).toBe(1);
467467
});
468468

469-
test("should split into correct number of pipelines for large batches", async () => {
469+
test("should split 2*MAX_PIPELINE_SIZE + 500 commands into three pipelines", async () => {
470470
const redis = Redis.fromEnv({
471471
latencyLogging: false,
472472
enableAutoPipelining: true,
@@ -490,7 +490,7 @@ describe("Auto pipeline", () => {
490490
});
491491

492492
describe("read/write pipeline separation", () => {
493-
test("should use separate pipelines for reads and writes", async () => {
493+
test("should split a Promise.all of mixed reads and writes into one read pipeline and one write pipeline", async () => {
494494
const redis = Redis.fromEnv({
495495
latencyLogging: false,
496496
enableAutoPipelining: true,
@@ -518,7 +518,7 @@ describe("Auto pipeline", () => {
518518
expect(redis.pipelineCounter).toBe(2);
519519
});
520520

521-
test("should use a single pipeline for only reads", async () => {
521+
test("should batch a Promise.all of only reads into a single read pipeline", async () => {
522522
const redis = Redis.fromEnv({
523523
latencyLogging: false,
524524
enableAutoPipelining: true,
@@ -547,7 +547,7 @@ describe("Auto pipeline", () => {
547547
expect(redis.pipelineCounter).toBe(2);
548548
});
549549

550-
test("should use a single pipeline for only writes", async () => {
550+
test("should batch a Promise.all of only writes into a single write pipeline", async () => {
551551
const redis = Redis.fromEnv({
552552
latencyLogging: false,
553553
enableAutoPipelining: true,
@@ -571,7 +571,7 @@ describe("Auto pipeline", () => {
571571
expect(redis.pipelineCounter).toBe(1);
572572
});
573573

574-
test("should separate JSON reads and writes into different pipelines", async () => {
574+
test("should split a Promise.all of json.set and json.get into separate write and read pipelines", async () => {
575575
const redis = Redis.fromEnv({
576576
latencyLogging: false,
577577
enableAutoPipelining: true,
@@ -594,7 +594,7 @@ describe("Auto pipeline", () => {
594594
expect(redis.pipelineCounter).toBe(2);
595595
});
596596

597-
test("should route reads to the read pipeline and writes to the write pipeline", async () => {
597+
test("should route each queued command to the active read or write pipeline based on its type and preserve insertion order", async () => {
598598
const redis = Redis.fromEnv({
599599
latencyLogging: false,
600600
enableAutoPipelining: true,
@@ -634,7 +634,7 @@ describe("Auto pipeline", () => {
634634
expect(redis.pipelineCounter).toBe(2);
635635
});
636636

637-
test("should route only reads to the read pipeline when no writes are issued", async () => {
637+
test("should leave the write pipeline null and queue all commands on the read pipeline when only reads are issued", async () => {
638638
const redis = Redis.fromEnv({
639639
latencyLogging: false,
640640
enableAutoPipelining: true,
@@ -656,7 +656,7 @@ describe("Auto pipeline", () => {
656656
expect(redis.pipelineCounter).toBe(1);
657657
});
658658

659-
test("should route only writes to the write pipeline when no reads are issued", async () => {
659+
test("should leave the read pipeline null and queue all commands on the write pipeline when only writes are issued", async () => {
660660
const redis = Redis.fromEnv({
661661
latencyLogging: false,
662662
enableAutoPipelining: true,
@@ -684,7 +684,7 @@ describe("Auto pipeline", () => {
684684
expect(redis.pipelineCounter).toBe(1);
685685
});
686686

687-
test("should route JSON reads and writes to their respective pipelines", async () => {
687+
test("should route JSON.GET/ARRLEN/OBJKEYS to the read pipeline and JSON.SET/ARRAPPEND/MERGE to the write pipeline", async () => {
688688
const redis = Redis.fromEnv({
689689
latencyLogging: false,
690690
enableAutoPipelining: true,
@@ -723,7 +723,7 @@ describe("Auto pipeline", () => {
723723
});
724724

725725
describe("excluded commands", () => {
726-
test("should not exclude set", async () => {
726+
test("should auto-pipeline set rather than treat it as an excluded command", async () => {
727727
const redis = Redis.fromEnv();
728728
// @ts-expect-error pipelineCounter is not in type but accessible
729729
expect(redis.pipelineCounter).toBe(0);
@@ -734,7 +734,7 @@ describe("Auto pipeline", () => {
734734
expect(redis.pipelineCounter).toBe(1);
735735
});
736736

737-
test("should exclude some commands", async () => {
737+
test("should bypass auto-pipelining for scan, keys, flushdb, flushall, dbsize, and exec", async () => {
738738
const redis = Redis.fromEnv({});
739739

740740
// @ts-expect-error pipelineCounter is not in type but accessible

packages/redis/pkg/auto-pipeline.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type redisOnly = Exclude<keyof Redis, keyof Pipeline>;
1010

1111
export const MAX_PIPELINE_SIZE = 1000;
1212

13-
export const READ_COMMANDS: Set<string> = new Set([
13+
const READ_COMMANDS: Set<string> = new Set([
1414
// String
1515
"get",
1616
"getrange",
@@ -68,6 +68,7 @@ export const READ_COMMANDS: Set<string> = new Set([
6868
"ttl",
6969
"pttl",
7070
"randomkey",
71+
"touch",
7172
// HyperLogLog
7273
"pfcount",
7374
// Stream
@@ -86,7 +87,6 @@ export const READ_COMMANDS: Set<string> = new Set([
8687
"scriptExists",
8788
"evalRo",
8889
"evalshaRo",
89-
"fcallRo",
9090
// Utility
9191
"dbsize",
9292
"echo",

0 commit comments

Comments
 (0)