首页 > 解决方案 > 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

标签: javascriptnode.jsredis

解决方案


hset需要一组特定的参数

client.hset("hash key", "hashtest 1", "some value", redis.print);

散列键,在散列中设置的键,我们正在设置的值,以及一个可选的回调。

您不能像尝试那样设置任意数量的键/值对。库看到您的第四个参数 ( 'myId') 并将其视为一个函数,这会导致错误。


推荐阅读