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

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

Closed
lemon707 opened this issue May 9, 2017 · 3 comments
Labels

Comments

@lemon707
Copy link

lemon707 commented May 9, 2017

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!

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)```

@BridgeAR
Copy link
Contributor

BridgeAR commented May 9, 2017

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.

@pireslopes
Copy link

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

@ad34
Copy link

ad34 commented Nov 12, 2018

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

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

4 participants