Skip to content

Commit deb999c

Browse files
committed
feat: exclude some commands from auto pipeline
excluded some commands that may take a long time from the auto pipeline
1 parent 234eaef commit deb999c

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

pkg/auto-pipeline.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ describe("Auto pipeline", () => {
162162
]);
163163
expect(result).toBeTruthy();
164164
expect(result.length).toBe(134); // returns
165-
// @ts-expect-error pipelineCounter is not in type but accessible120 results
165+
166+
// @ts-expect-error pipelineCounter is not in type but accessible results
166167
expect(redis.pipelineCounter).toBe(1);
167168
});
168169

@@ -376,4 +377,33 @@ describe("Auto pipeline", () => {
376377
const result = await redis.get("foobar");
377378
expect(result).toBe("foobar");
378379
});
380+
381+
describe("excluded commands", () => {
382+
test("should not exclude set", async () => {
383+
const redis = Redis.fromEnv();
384+
// @ts-expect-error pipelineCounter is not in type but accessible
385+
expect(redis.pipelineCounter).toBe(0);
386+
387+
await redis.set("foo", "bar");
388+
389+
// @ts-expect-error pipelineCounter is not in type but accessible
390+
expect(redis.pipelineCounter).toBe(1);
391+
});
392+
393+
test("should exclude some commands", async () => {
394+
const redis = Redis.fromEnv({});
395+
396+
// @ts-expect-error pipelineCounter is not in type but accessible
397+
expect(redis.pipelineCounter).toBe(0);
398+
399+
await redis.scan(0, { count: 1 });
400+
await redis.keys("some-random-pattern");
401+
await redis.flushdb();
402+
await redis.flushall();
403+
await redis.dbsize();
404+
405+
// @ts-expect-error pipelineCounter is not in type but accessible
406+
expect(redis.pipelineCounter).toBe(0);
407+
});
408+
});
379409
});

pkg/auto-pipeline.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import type { CommandArgs } from "./types";
88
// properties which are only available in redis
99
type redisOnly = Exclude<keyof Redis, keyof Pipeline>;
1010

11+
export const EXCLUDE_COMMANDS: Set<keyof Redis> = new Set([
12+
"scan",
13+
"keys",
14+
"flushdb",
15+
"flushall",
16+
"dbsize",
17+
]);
18+
1119
export function createAutoPipelineProxy(_redis: Redis, json?: boolean): Redis {
1220
const redis = _redis as Redis & {
1321
autoPipelineExecutor: AutoPipelineExecutor;
@@ -30,8 +38,9 @@ export function createAutoPipelineProxy(_redis: Redis, json?: boolean): Redis {
3038

3139
const commandInRedisButNotPipeline =
3240
command in redis && !(command in redis.autoPipelineExecutor.pipeline);
41+
const isCommandExcluded = EXCLUDE_COMMANDS.has(command as keyof Redis);
3342

34-
if (commandInRedisButNotPipeline) {
43+
if (commandInRedisButNotPipeline || isCommandExcluded) {
3544
return redis[command as redisOnly];
3645
}
3746

0 commit comments

Comments
 (0)