首页 > 解决方案 > 如何将哈希存储在 Redis 的列表中?

问题描述

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

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);
});

请帮帮我。

标签: node.jsredis

解决方案


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);
});

推荐阅读