Node-redis: ERR wrong number of arguments for 'hmset' command

Created on 6 Sep 2012  ·  10Comments  ·  Source: NodeRedis/node-redis

after npm update the problem appear with node-redis

node_redis: no callback to send error: Error: ERR wrong number of arguments for 'hmset' command

/var/www/node_modules/redis/index.js:475
throw err;
^
Error: Error: ERR wrong number of arguments for 'hmset' command
at HiredisReplyParser.RedisClient.init_parser (/var/www/node_modules/redis/index.js:253:27)
at HiredisReplyParser.EventEmitter.emit (events.js:88:17)
at HiredisReplyParser.execute (/var/www/node_modules/redis/lib/parser/hiredis.js:41:18)
at RedisClient.on_data (/var/www/node_modules/redis/index.js:440:27)
at Socket. (/var/www/node_modules/redis/index.js:70:14)
at Socket.EventEmitter.emit (events.js:88:17)
at TCP.onread (net.js:395:14)

I have node 0.8.8 and npm 1.1.59

bug fixed / done

All 10 comments

I found, that it is caused by local problem with project code, but the error message is really not obvious.

Would you mind saying what the problem was? I'd be happy to make the error
message more informative.

Cheers
On Sep 6, 2012 5:48 PM, "Yuri Karadzhov" [email protected] wrote:

I found, that it is caused by local problem with project code, but the
error message is really not obvious.


Reply to this email directly or view it on GitHubhttps://github.com/mranney/node_redis/issues/262#issuecomment-8348897.

I'm not really sure, but as I understand the problem was - node use precompiled version of the project to run. As I delete app.js.orig file it start workine just fine. But it still looks like a mistics for me.

In the old version of app.js I use redis call to hash and pass an object as a parametr, but the problem was - the object has some undefined fields and it cause similar problem with redis-client. The error message was informative and show me the stack which leads to that redis call.

Then I fixed this problem by removing this empty fields from th object. And I get the problem discribed above.

One way for this error to occur is passing an integer as the first parameter of hmset. I fixed this by converting the first parameter to a string in my code.

Maybe node_redis should do this automatically if the first parameter is a number?

This is what I'm getting, not sure what I'm doing wrong. Redis docs didn't say if the key had to exist previously, so I don't think that should matter. The command works in redis-cli

// opts.value = { ... };
return redis.hmset(key, opts.value);


TRACE:09:23:52:Sending to Redis: hmset token:8659171012f5422aac2f7777890eb6e8 "id" "8659171012f5422aac2f7777890eb6e8" "value" "5hJPYT2rPSUnbfSms7bFuNgwCvo" "ttl" "86400" - lib/redis::bind
     lib/redis::bind
     lib/redis::bind
send redis-d001.liveclips.net:6379 id 1: *3
$5
hmset
$38
token:8659171012f5422aac2f7777890eb6e8
$91
"id" "8659171012f5422aac2f7777890eb6e8" "value" "5hJPYT2rPSUnbfSms7bFuNgwCvo" "ttl" "86400"

send_command buffered_writes: 0  should_buffer: false
net read redis-d001.liveclips.net:6379 id 1: -ERR wrong number of arguments for 'hmset' command

Can't send an object - so I'm converting the object to the key value pairs, and still doesn't work:

var args = [key].concat(obj_to_kvp(opts.value));
return redis.hmset.apply(redis, args);


TRACE:09:29:10:Sending to Redis: hmset token:903acf5ac512481a921e9215b643a604 "id" "903acf5ac512481a921e9215b643a604" "value" "5hJPYT2rPSUnbfSms7bFuNgwCvo" "ttl" "86400" - lib/redis::bind
     lib/redis::bind
     lib/redis::bind
send redis-d001.liveclips.net:6379 id 1: *3
$5
hmset
$38
token:903acf5ac512481a921e9215b643a604
$91
"id" "903acf5ac512481a921e9215b643a604" "value" "5hJPYT2rPSUnbfSms7bFuNgwCvo" "ttl" "86400"

send_command buffered_writes: 0  should_buffer: false
net read redis-d001.liveclips.net:6379 id 1: -ERR wrong number of arguments for 'hmset' command

For some reason it didn't think of the arguments was a string, I had to iterate through the object and explicitly set each key and value to a string.

It seems only the first argument must be a string. The object with values could be numbers or strings.

redis.hmset("key", {"id": 5, somekey: "someval"}); //will work
redis.hmset(1, {"id": 5, somekey: "someval"}); //will not work

Added toString() conversion in client.hmset(key, object, [callback]) to fix this issue. HMSET function can now accept numbers (e.g. timestamps), although they are sent to Redis as strings. See code here: https://github.com/ralexstokes/node_redis/blob/master/index.js, beginning line 1036.

你的某一个变量名或者函数的参数名与库发生冲突了,建议该参数名就好了。 我刚刚也遇到这个问题。

This is fixed in newer versions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  ·  3Comments

gpascale picture gpascale  ·  4Comments

michaelwittig picture michaelwittig  ·  3Comments

jackycchen picture jackycchen  ·  4Comments

Stono picture Stono  ·  6Comments