node.js - 如何将哈希存储在 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);
});
请帮帮我。
解决方案
在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);
});
推荐阅读
- f# - F#如何使用匿名类型代替完整类型的变量
- python - 在python中连接wifi的最简单方法
- pandas-datareader - '使用 pandas-datareader 时出错:没有使用 'YahooDailyReader' 获取数据
- html - 在 Cpanel 中安装新字体
- assembly - MIPS 32 显示错误值并重复打印语句
- node.js - 如何在连接范围之外引用 socket.id 或以可以在连接范围之外引用的方式存储它?
- electron - 在具有上下文隔离的渲染器中使用电子保存对话框
- c# - 总偶数数组
- java - 在java中创建类对象而不使用类名方法的替代方法
- javascript - 如何获取数组中唯一值的*索引*