3

I am using https://github.com/mranney/node_redis and trying to update a set with multiple values at once (on redis cli "SADD myset val1 val2" works fine).

The exact command I am using is:

var cmd_array = ['myset', 'val1', 'val2'];
client.sadd(cmd_array);

Based on their documentation this should of worked. Any idea why it doesn't?

Thanks

0

1 Answer 1

8

It works fine for me. I can run the following script without any issue:

var redis = require("redis"),
    client_options = {
    parser: "hiredis"
};

var credis = redis.createClient( '/tmp/redis.sock', client_options );

function main()
{
   credis.flushall( function(err,res) {
      console.log( "hello" );
      x = [ "X", "A", "B", "C" ];
      credis.sadd(x);
      credis.sadd( "myset", x, function(err,res) {
         console.log("done");
         credis.end();
      });
   });
}

main();

It creates the two keys with the expected number of items:

redis 127.0.0.1:6379> keys *                                                                                                                                                                                                                 
1) "X"                                                                                                                                                                                                                                       
2) "myset"                                                                                                                                                                                                                                   
redis 127.0.0.1:6379> smembers myset                                                                                                                                                                                                         
1) "X"                                                                                                                                                                                                                                       
2) "A"                                                                                                                                                                                                                                       
3) "B"                                                                                                                                                                                                                                       
4) "C"                                                                                                                                                                                                                                       
redis 127.0.0.1:6379> smembers X                                                                                                                                                                                                             
1) "A"                                                                                                                                                                                                                                       
2) "B"                                                                                                                                                                                                                                       
3) "C"                                                                                                                                                                                                                                       

I would suggest you check the node_redis version. The version I use is:

$ npm list
/home/dspezia/local/test_redis
├── [email protected] 
└── [email protected] 
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you Didier for your reply. I am using version 0.7.2, by the way the exact error I am getting is "Error: Error: Error: ERR wrong number of arguments for 'sadd' command"
Just ran your code on the version I have got installed (0.7.2) and it throws the same error. questions is whether its a problem with my installation or the version.
I have upgraded to 0.7.2, and it still works fine for me. There is also node.js version itself to check. Do you use a dev branch (i.e. version > 0.6.16)?
One last bit, which version of redis server are you using? mine is Redis server version 2.2.12 (00000000:0)
Ah, that's probably it. Redis 2.2 is quite old now. Variadic parameters commands have been added with 2.4. Changelog here: github.com/antirez/redis/raw/2.4/00-RELEASENOTES
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.