gpt4 book ai didi

node.js - 如何在 Redis 的列表中存储哈希值?

转载 作者:可可西里 更新时间:2023-11-01 11:15:17 24 4
gpt4 key购买 nike

Redis 对我来说是新手,我想将 Hashes 存储在 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);
});

请帮帮我。

最佳答案

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

关于node.js - 如何在 Redis 的列表中存储哈希值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50656376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com