Ali Asgher Badshah
Ali Asgher Badshah

Reputation: 851

How to store Hashes in Lists in Redis?

Redis is new for me and i wanted to store the Hashes in List in redis but i unable to do that and i get the error

node_redis: Deprecated: The RPUSH 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.

This is my code:

let object ={
    name:'jhone doe',
    age:25
};
client.rpush(['key', object], function(err, reply) {
    if(err){
        console.log(err);
    }
    console.log(reply);
});

Please help me out.

Upvotes: 0

Views: 468

Answers (1)

Evhz
Evhz

Reputation: 9248

In Redis, store the string version of the object. Do it like this:

let obj={
    name:'jhone doe',
    age:25
};
client.rpush(['key', JSON.stringify(obj)], function(err, reply) {
   if (err){
       console.log(err);
    }
    console.log(reply);
});

Upvotes: 1

Related Questions