yeahoffline / redis-mock

Node.js redis client mock
213 stars 111 forks source link

Use of arrays as command arguments #83

Closed mapolonio closed 5 years ago

mapolonio commented 6 years ago

In the node_redis official documentation they state that arrays can be used along with individual arguments (see https://github.com/NodeRedis/node_redis#sending-commands). But in redis-mock the behaviour is not the same:

(I have promisified the client)

const client = redis.createClient();

await client.saddAsync('mySet', ['a', 'b', 'c']);

const members = await client.smembersAsync('mySet');

console.log(members);
// In node_redis: ['a', 'b', 'c'] (3 members)
// In redis-mock: '["a", "b", "c"]' (1 member, the array stringified)
hugoduraes commented 5 years ago

Just stumbled upon this issue. Can it be fixed?

mapolonio commented 5 years ago

I ended up doing something like this

const originalMethod = client.saddAsync;

client.saddAsync = function(...args) {
      return originalMethod(..._.flatten(args));
};
hugoduraes commented 5 years ago

@yeahoffline I've just created a PR to fix this issue. Can you have a look at it? Thanks.