I have Python code:
redis.sadd(r_key, *set(r_list))
and it works excellent: But I can't do the same on Node.js
redis.sadd(r_key, new Set(array), function(err) {})
What am I doing wrong ?
I have Python code:
redis.sadd(r_key, *set(r_list))
and it works excellent: But I can't do the same on Node.js
redis.sadd(r_key, new Set(array), function(err) {})
What am I doing wrong ?
Actually, this is a problem about how to use flatten args in Js like python *.
You can read this doc https://www.npmjs.com/package/redis, It said, all the redis api is 1 to 1 mapping of redis server command. so SADD is :
SADD key member [member ...]
Your js code should be like above. just a case:
redis.sadd("key","member", "member", ...)
So you know why you code does not work.
To do this, you can refer this question : Python-like unpacking in JavaScript
redis.sadd.apply(this, args)
And the args is a array of key and your members string .