Skip to content


Subversion checkout URL

You can clone with
Download ZIP


hmset broken #218

pyrotechnick opened this Issue · 7 comments

3 participants


When passed an object of arrays, HMSET screws up in strange ways...

  var client, redis;

  redis = require('redis');

  client = redis.createClient();

  client.hmset('foo', {
    a: [0, 0, 0]

  client.hmset('foo', {
    a: [0, 0, 0],
    b: [0, 0, 0]

  client.hmset('foo', {
    a: [0, 0, 0],
    b: [0, 0, 0],
    c: 'bar'

redis-cli monitor

1337435337.689485 "hmset" "foo" "a" "0" "0" "0"
1337435337.689667 "hmset" "foo" "a" "0,0,0" "b" "0" "0" "0"
1337435337.689744 "hmset" "foo" "a" "0,0,0" "b" "0,0,0" "c" "bar"

N.B. It only breaks if the last key of the object is an array.

This was a real PITA to find. I presume something is broken somewhere deep inside all the voodoo of RedisClient.prototype.hmset (


hmm this also happens with client.hmset(hash, key1, val1, ... keyn, valn, [callback])

client.hmset('foo', 'a', [0, 0, 0]);
client.hmset('foo', 'a', [0, 0, 0], 'b', [0, 0, 0]);
client.hmset('foo', 'a', [0, 0, 0], 'b', [0, 0, 0], 'c', 'bar');

redis-cli monitor

"hmset" "foo" "a" "0" "0" "0"
"hmset" "foo" "a" "0,0,0" "b" "0" "0" "0"
"hmset" "foo" "a" "0,0,0" "b" "0,0,0" "c" "bar"

We need to go deeper...


So I've traced the issue down to the lines

    // if the last argument is an array, expand it out.  This allows commands like this:
    //     client.command(arg1, [arg2, arg3, arg4], cb);
    //  and converts to:
    //     client.command(arg1, arg2, arg3, arg4, cb);
    // which is convenient for some things like sadd
    if (args.length > 0 && Array.isArray(args[args.length - 1])) {
        args = args.slice(0, -1).concat(args[args.length - 1]);

in RedisClient.prototype.send_command

I suppose only strings are officially supported by node_redis and not arrays as I have been using. Nevertheless, I still believe there is an issue here as the current behaviour is somewhat unintuitive.


Is the conclusion that

should say "user strings!"?

Alternatively, it could throw an error when the thing is not a string?
Alternatively, it could JSON.parse if not a string.




Gonna go with: mention it in the docs, and callback &/or throw when a string is not passed in.


@DTrejo DTrejo closed this in b60e001

Well I'd love to have arrays functionality here if you still care


@mciparelli pull requests are welcome!

@DTrejo DTrejo referenced this issue from a commit
@mciparelli mciparelli fixes #218 by expanding last argument array only for sadd command
Also adds a test that uses SADD in caps. Nicely enough, this makes
multi_bench.js run just a tiny bit faster :)

Signed-off-by: DTrejo <>

I don't think that 124ea08 allows you to give arrays, even if you revert b60e001. It does make things faster though, so still worth writing.

If someone feels like adding a test for allowing arrays instead of only strings, please git revert b60e001 , and then take a go at it.


@TheDeveloper TheDeveloper referenced this issue from a commit in TheDeveloper/node_redis
@TheDeveloper TheDeveloper Consolidate special hash helpers for client + multi client.
Addresses #218: Allow strings and integer in obj for hmset(key, obj)
Fixes #272: Parse array arg consistently for client and multi
@DTrejo DTrejo referenced this issue from a commit
@DTrejo DTrejo Revert "hmset throws/errors out on non-string values. fixes #218"
Reverting because this was a documentation problem, not a problem with
the code. Performance-wise, this is faster than the approach in #345, though
it may cause users more trouble. This is okay, if someone opens an issue we
can point them to the docs.

This reverts commit b60e001.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.