redis-mock icon indicating copy to clipboard operation
redis-mock copied to clipboard

HMSET command behavior difference

Open pejrak opened this issue 2 years ago • 0 comments

Hi there again. I have another difference in behavior for HMSET command in redis-mock compared to redis package.

When redis-mock is used to HMSET an 'empty' object as payload on a key, it will return undefined, but it won't call the callback.

const redisMock = require('redis-mock')
const mdb = redisMock.createClient()
mdb.hmset('hello', {}, function() { console.log('done', arguments) } ) ==> undefined

When you use the redis package, the command itself returns true, but callback throws an error.

const redis = require('redis')
const rdb = redis.createClient()
rdb.hmset('hello', {}, function() { console.log('done', arguments) } ) ==>  true

> done [Arguments] {
  '0': ReplyError: ERR wrong number of arguments for 'hmset' command
      at parseError (/var/www/kawa/app/node_modules/redis-parser/lib/parser.js:179:12)
      at parseType (/var/www/kawa/app/node_modules/redis-parser/lib/parser.js:302:14) {
    command: 'HMSET',
    args: [ 'hello' ],
    code: 'ERR'
  },
  '1': undefined
}

Runtime: node.js v16.13.1

Npm packages: redis-mock v0.56.3 redis v3.1.2

I will work on the PR for this, unless you want more details or have other suggestions.

pejrak avatar Apr 26 '22 13:04 pejrak