Skip to content

Commit 4bf0be7

Browse files
authored
fix: resolve arrappend issue (#1165)
when a redis method which is available in .json but not available in the pipeline is used while auto pipeline is enabled, proxy doesn't check properly that the method is a function and attempts to return from pipeline, instead of pipeline.json.
1 parent c00b02d commit 4bf0be7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pkg/auto-pipeline.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe("Auto pipeline", () => {
1313
test("should execute all commands inside a Promise.all in a single pipeline", async () => {
1414
const persistentKey = newKey();
1515
const persistentKey2 = newKey();
16+
const persistentKey3 = newKey();
1617
const scriptHash = await new ScriptLoadCommand(["return 1"]).exec(client);
1718

1819
const redis = Redis.fromEnv({
@@ -143,10 +144,11 @@ describe("Auto pipeline", () => {
143144
redis.zscore(newKey(), "member"),
144145
redis.zunionstore(newKey(), 1, [newKey()]),
145146
redis.zunion(1, [newKey()]),
146-
redis.json.set(newKey(), "$", { hello: "world" }),
147+
redis.json.set(persistentKey3, '$', { log: ["one", "two"] }),
148+
redis.json.arrappend(persistentKey3, "$.log", '"three"'),
147149
]);
148150
expect(result).toBeTruthy();
149-
expect(result.length).toBe(120); // returns
151+
expect(result.length).toBe(121); // returns
150152
// @ts-expect-error pipelineCounter is not in type but accessible120 results
151153
expect(redis.pipelineCounter).toBe(1);
152154
});

pkg/auto-pipeline.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export function createAutoPipelineProxy(_redis: Redis, json?: boolean): Redis {
3434
}
3535

3636
// If the method is a function on the pipeline, wrap it with the executor logic
37-
if (typeof redis.autoPipelineExecutor.pipeline[command as keyof Pipeline] === "function") {
37+
const isFunction = json
38+
? typeof redis.autoPipelineExecutor.pipeline.json[command as keyof Pipeline["json"]] === "function"
39+
: typeof redis.autoPipelineExecutor.pipeline[command as keyof Pipeline] === "function"
40+
if (isFunction) {
3841
return (...args: CommandArgs<typeof Command>) => {
3942
// pass the function as a callback
4043
return redis.autoPipelineExecutor.withAutoPipeline((pipeline) => {

0 commit comments

Comments
 (0)