在Node.js App中创建REDIS数据库时,我会遇到类型错误
我正在尝试将set添加到node.js应用中的redis数据库中:
let redisConnect = async () => {
redisClient.on('error', (err) => {
console.log('Redis Client Error', err);
});
redisClient.on('ready', () => console.log('Redis is ready'));
await redisClient.connect();
redisClient.sadd(['tags', 'angularjs', 'reactjs', 'nodejs'], function(err, reply) {
console.log(reply);
});
};
redisConnect();
此错误是抛出的: typeError:redisclient.sadd不是
我能够在列表或字符串(例如list或string)上设置其他redis数据库类型的函数。
I am trying to add a set to a redis database in a node.js app like this:
let redisConnect = async () => {
redisClient.on('error', (err) => {
console.log('Redis Client Error', err);
});
redisClient.on('ready', () => console.log('Redis is ready'));
await redisClient.connect();
redisClient.sadd(['tags', 'angularjs', 'reactjs', 'nodejs'], function(err, reply) {
console.log(reply);
});
};
redisConnect();
This error is thrown:
TypeError: redisClient.sadd is not a function
I am able to set other Redis database types on this client like list or string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不完全理解如何解决这个问题。我从Redis库切换到Ioredis,并摆脱了:
并添加了“等待”,
我认为redisclient.connect()可能是多余的。当我切换到Ioredis时,这引发了错误:
可能有人会为此解决方案提供解释。
I do not understand fully how I solved this problem. I switched from the redis library to ioredis and got rid of:
and added 'await' to
I think the redisClient.connect( ) might have been redundant. This threw an error when I switched to ioredis :
Possibly someone will have an explanation for this solution.