Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMSET under v4 doesn't work. HSET does #1746

Closed
BarryCarlyon opened this issue Nov 29, 2021 · 5 comments
Closed

HMSET under v4 doesn't work. HSET does #1746

BarryCarlyon opened this issue Nov 29, 2021 · 5 comments
Labels

Comments

@BarryCarlyon
Copy link

BarryCarlyon commented Nov 29, 2021

HMSET does not seem to be supported

I have to resort to sendcommand instead?

                redis_client.HMSET(
                    'test_key',
                    'some_key',
                    'some_value',
                    'another_key',
                    'another_value'
                )
                .then(r => {
                    console.log(r);
                })
                .catch(e => {
                    console.error(e);
                });

and

                let r = await redis_client.HMSET(
                    'test_key',
                    'some_key',
                    'some_value',
                    'another_key',
                    'another_value'
                )

Results in

                redis_client.HMSET(
                             ^

TypeError: redis_client.HMSET is not a function

Additionally, after

127.0.0.1:6379> hset test_key some_key a another_key thing

HMGET can't get multiple keys?

                let ra = await redis_client.HMGET(
                    'test_key',
                    'some_key',
                    'some_value',
                    'another_key',
                    'another_value'
                )
                console.log(ra);

results in

[ 'a' ]

Or is this a case of "node redis doesn't know about this yet" but it did in the last v3 version?

Environment:

  • Node.js Version: v16.9.0
  • Redis Server Version: v=6.2.6 sha=00000000:0 malloc=libc bits=64 build=c6f3693d1aced7
  • Node Redis Version: redis@4.0.0
  • Platform: Mac 12.0.1
@leibale
Copy link
Collaborator

leibale commented Nov 29, 2021

HMSET is deprecated since redis 4.0.0, you can use HSET to set multiple fields as well:

// with an object
client.HSET('key', {
  field1: 'value1',
  field2: 'value2'
});

// with flat array
client.HSET('key', ['field1', 'value1', 'field2', 'value2']);

// with tuples
client.HSET('key', [['field1', 'value1'], ['field2', 'value2']]);

for MGET, instead of passing the field names as multiple arguments, pass them as an array:

client.HMGET('key', ['field1', 'field2']);

@leibale leibale closed this as completed Nov 29, 2021
@BarryCarlyon
Copy link
Author

This might be the sort of thing to include/add to the migration guide perhaps?

@djaffer
Copy link

djaffer commented Dec 2, 2021

It is due to commands becoming camel case and if you were using a lower case like hset then you would hit this issue. Not the best way of releasing a new release. I was stuck on this too.
#1760

@madprops
Copy link

you can use HSET to set multiple fields as well

Why then use the example with HMSET, this confused me.

@Scorpiour
Copy link

HMSET is deprecated since redis 4.0.0, you can use HSET to set multiple fields as well:

// with an object
client.HSET('key', {
  field1: 'value1',
  field2: 'value2'
});

// with flat array
client.HSET('key', ['field1', 'value1', 'field2', 'value2']);

// with tuples
client.HSET('key', [['field1', 'value1'], ['field2', 'value2']]);

for MGET, instead of passing the field names as multiple arguments, pass them as an array:

client.HMGET('key', ['field1', 'field2']);

Your example doesn't work on 4.6.11, while there is an error of [ErrorReply: ERR wrong number of arguments for 'hset' command]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants