redis / node-redis

Redis Node.js client

Home Page:https://redis.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XCLAIM exception on ejected value

SiyahaS opened this issue · comments

Node.js Version: 16.15.0
Node Redis Version: ^4.5.1
Platform: Docker for Windows(redis/redis-stack image 0ac5d4d8535e)

When calling XCLAIM on an ejected value an exception is thrown with insufficient information. XCLAIM should return null or an array with null entry for ejected identifiers.

await redis.XADD("stream", "0-0", { "test": 1 }, { TRIM: { strategy: "MAXLEN", strategyModifier: "=", threshold: 1, limit: 1 }  });
await redis.XREADGROUP("group", "consumer-1", { key: "stream", id: "0" }); // process 1
await redis.XADD("stream", "0-1", { "test": 1 }, { TRIM: { strategy: "MAXLEN", strategyModifier: "=", threshold: 1, limit: 1 }  });
await redis.XREADGROUP("group", "consumer-2", { key: "stream", id: "0" }); // process 2
await redis.XCLAIM("stream", "group", "consumer-2", 0, "0-0") // process 2

// ERROR
...\node_modules\@redis\client\dist\lib\commands\generic-transformers.js:71
    for (const [id, message] of reply) {
                           ^

TypeError: .for is not iterable
    at Object.transformStreamMessagesReply (...\node_modules\@redis\client\dist\lib\commands\generic-transformers.js:71:28)
    at transformCommandReply (...\node_modules\@redis\client\dist\lib\commander.js:88:20)
    at Commander.commandsExecutor (...\node_modules\@redis\client\dist\lib\client\index.js:177:54)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

@SiyahaS first of all, sorry for the delay...
I tried to run the code above, but it throws "Invalid argument type" because { test: 1 } is not a valid stream message - only strings and buffers are supported. I tried to change that to { test: '1' }, but then I got "ERR syntax error, LIMIT cannot be used without the special ~ option"... can you please provide a "working" example?

Hello @leibale, I forgot to check on this sorry about that. I too cannot replicate this behavior anymore. I think we can close this issue.

PS: After removing limit=1 from XREADGROUP code is able to run.

PS2: Third argument of XADD is type of Record<string, any> and gives a false information in that regard. I guess you should change it so Record<string, string|Buffer> if that is the case but I'm not really good on Typescript so I might be talking nonsense.

@SiyahaS thanks for helping :)

regarding the third argument type, the type is Record<string, RedisCommandArgument>, and RedisCommandArgument is string | Buffer
https://github.com/redis/node-redis/blob/master/packages/client/lib/commands/XADD.ts#L18
https://github.com/redis/node-redis/blob/master/packages/client/lib/commands/index.ts#L7