javascript - redis UnhandledPromiseRejectionWarning: TypeError: command_obj.callback is not a function
问题描述
简单的nodejs和redis代码在我使用它时将数据设置到redis中,client.set(key,value)
但是当我hset
像这样使用时:
const fields = [ 'partnerId', '1404798351','myId','23423423' ] //this is a simple example
const client = createClient({ url: process.env.REDIS_URL });
client.hset(`chat:252353453`, ...fields)
它返回此错误:
UnhandledPromiseRejectionWarning: TypeError: command_obj.callback is not a function
解决方案
hset
需要一组特定的参数:
client.hset("hash key", "hashtest 1", "some value", redis.print);
散列键,在散列中设置的键,我们正在设置的值,以及一个可选的回调。
您不能像尝试那样设置任意数量的键/值对。库看到您的第四个参数 ( 'myId'
) 并将其视为一个函数,这会导致错误。
推荐阅读
- google-api - “Google Contacts CardDAV API”会在 2021 年夏天与“Contacts API”一起关闭吗?
- api - 无法使用 apikey 连接/命中端点
- java - Java jar(API) 或微服务 - 用于 java 和 python 项目
- ios - iOS Homekit 错误:缺少 API HomeKit 的权利
- c - 如何返回C中每一行的最后一个元素
- mysql - 有什么办法可以填写mysql information_schema.TRIGGERS.created = now()
- .net-core - 使用带有 NHibernate 的 Web api 通过 JSON 插入嵌套对象
- azure - azure yaml 构建管道的摘要选项卡上显示不正确的代码覆盖率百分比
- python - 按 ID 对数据框进行分组并列出文章
- winforms - window.external 对于新窗口为空