如何在Redis列表中存储哈希?

时间:2018-06-02 11:19:11

标签: node.js redis

Redis对我来说是新的,我想在redis中存储列表中的哈希,但我无法做到这一点,我得到了错误

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.

这是我的代码:

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

请帮帮我。

1 个答案:

答案 0 :(得分:1)

Redis中,存储对象的字符串版本。这样做:

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