Node-redis: Error with node-redis: Deprecated: The SET command contains a argument of type Object

Created on 9 May 2017  路  3Comments  路  Source: NodeRedis/node-redis

Also posted on Stack Overflow: http://stackoverflow.com/questions/43858414/error-with-node-redis-deprecated-the-set-command-contains-a-argument-of-type-o

I'm using the connect-redis-crypto module (https://github.com/jas-/connect-redis-crypto ) which is built for encrypting redis session data on top of connect-redis(https://github.com/tj/connect-redis). My redis version is 3.2.8.

I am running into error node-redis: Deprecated: The SET command contains a argument of type Object. Based on the larger error message, it seems to come from trying to parse the string [object Object] when it is not a JSON string. I put nested objects that hold user information on req.session which directly gets stored (and ideally encrypted) in redis.

From some sources I learned nested objects in Redis are not allowed which might cause this error, but I believe this library stores data as JSON to allow for nested objects. connect-redis works fine for me, but when this connect-redis-crypto library tries to JSON parse encrypted data it throws me this particular error.

Would really appreciate your help!

node_redis: Deprecated: The SET command contains a argument of type Object. This is converted to "[object Object]" by using .toString() now and will return an error from v.3.0 on. Please handle this in your code to make sure everything works as you intended it to. 8 May 18:24:48 - ---NEW REQUEST--- REQUEST : GET /api/somePath/client QUERY : {} BODY : {} data [object Object] err SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>) at Command.callback (/Users/Documents/web-AOT/server/node_modules/connect-redis-crypto/lib/connect-redis.js:262:35) at normal_reply (/Users/Documents/web-AOT/server/node_modules/redis/index.js:721:21) at RedisClient.return_reply (/Users/Documents/web-AOT/server/node_modules/redis/index.js:819:9) at JavascriptRedisParser.returnReply (/Users/Documents/web-AOT/server/node_modules/redis/index.js:192:18) at JavascriptRedisParser.execute (/Users/Documents/web-AOT/server/node_modules/redis-parser/lib/parser.js:560:12) at Socket.<anonymous> (/Users/Documents/web-AOT/server/node_modules/redis/index.js:274:27) at emitOne (events.js:96:13) at Socket.emit (events.js:189:7) at readableAddChunk (_stream_readable.js:176:18) at Socket.Readable.push (_stream_readable.js:134:10) at TCP.onread (net.js:551:20)

question

Most helpful comment

node_redis does not stringify an object in case such is provided. The reason is, that it would not know when to parse the string and when not to.

Therefore you actually saved [object Object] in Redis, just as the warning indicates. And you run into the parse error because [object Object] is not valid JSON. So please stringify your object before passing it to node_redis.

All 3 comments

node_redis does not stringify an object in case such is provided. The reason is, that it would not know when to parse the string and when not to.

Therefore you actually saved [object Object] in Redis, just as the warning indicates. And you run into the parse error because [object Object] is not valid JSON. So please stringify your object before passing it to node_redis.

Use: client.set('key', JSON.stringify({example: {field: 'testing', field1: 333 }, field: 123}, () => {});
client.get('key', (err, data) => {
console.log(JSON.parse(data);
});

is it possible to have a callback on this warning ? it s always tricky to find the cause of theses warning on large projects.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shmendo picture shmendo  路  6Comments

dotSlashLu picture dotSlashLu  路  5Comments

Atala picture Atala  路  3Comments

Stono picture Stono  路  6Comments

jackycchen picture jackycchen  路  4Comments