Chris
Chris

Reputation: 461

Node Redis Client Not Working With Method "HMSET"

I have the following code block that fails:

this.redisClient.hmset('user:' + userObj.getUserId(), {
                'userId' : userObj.getUserId(),
                'salutation' : userObj.getSalutation(),
                'fn' : userObj.getFn(),
                'mi' : userObj.getMi(),
                'ln' : userObj.getLn(),
                'suffix' : userObj.getSuffix(),
                'userType' : userObj.getUserType(),
                'created' : userObj.getCreated()
            });

The error stack is as follows:

node.js:201
    throw e; // process.nextTick error, or 'error' event on first tick
          ^
TypeError: Cannot call method 'hmset' of undefined
at /node_apps/oc/api/v1/routes/user/db.user.js:70:34
at try_callback (/node_apps/oc/api/v1/node_modules/redis/index.js:484:9)
at RedisClient.return_reply (/node_apps/oc/api/v1/node_modules/redis/index.js:555:13)
at HiredisReplyParser.<anonymous> (/node_apps/oc/api/v1/node_modules/redis/index.js:256:14)
at HiredisReplyParser.emit (events.js:67:17)
at HiredisReplyParser.execute (/node_apps/oc/api/v1/node_modules/redis/lib/parser/hiredis.js:43:18)
at RedisClient.on_data (/node_apps/oc/api/v1/node_modules/redis/index.js:440:27)
at Socket.<anonymous> (/node_apps/oc/api/v1/node_modules/redis/index.js:70:14)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:329:14)

I am running Node 0.6.17 with Node Redis client. Any insight? Thanks!

Upvotes: 1

Views: 4954

Answers (1)

Michelle Tilley
Michelle Tilley

Reputation: 159105

If Node thinks you're calling hmset on undefined, that means it thinks that this.redisClient is undefined; quite often, this is because the value of this is not what you think it is (although it could be that redisClient wasn't initialized, etc). While it's impossible to say without seeing the surrounding code and how it's called, check to make sure the value of this is bound, if necessary.

Upvotes: 1

Related Questions