mmkal / handy-redis

A wrapper around node_redis with Promise and TypeScript support.
Apache License 2.0
172 stars 10 forks source link

Multi commands pass an array to the underlying redis function #277

Closed cfredhart closed 3 years ago

cfredhart commented 3 years ago

When setting up the commands for the WrappedNodeRedisClientImpl.prototype, the flattened array of parameters are passed using the spread operator in src/node_redis/index.ts#58,

return this.nodeRedis[method](...flattenedArgs);

however, the flattened array of parameters is passed without using the spread operator in src/node_redis/multi.ts#L61

(this as any).nodeRedisMulti[method](flattenDeep(args));

The result appears to be that for multi commands, the wrapped nodeRedis instance receives its parameters as a single array whereas non-multi functions receive their arguments as separate arguments. This seems to cause an issue when mocking the underlying redis instance with redis-mock since it does not correctly handle the parameters received from the multi functions.

mmkal commented 3 years ago

@cfredhart thanks for the report. I don't see why ... shouldn't be used for multis as well. This is only working now because the underlying client flattens args at runtime too (though ideally redis-mock should mirror that behaviour). Would you like to open a PR?

cfredhart commented 3 years ago

I can open a PR. I also have a PR open for redis-mock to flatten the args on that side.