为什么会出现这种hgetall类型的错误?

问题描述 投票:0回答:1

这是有问题的代码:

let key = "player:"+player_id;
console.log(key);
console.log(typeof(key));

redisClient.hgetall(key, function (err, result) {

if (err) { 
console.log(err);
res.end(false);
}

console.log("this is the reply");
console.log(result);
res.end(result);
});

这里是的console.log输出和错误:

player:5db138fdc0
string
this is the reply
{ name: 'Noah' }
_http_outgoing.js:739
      throw new TypeError('First argument must be a string or Buffer');
      ^

TypeError: First argument must be a string or Buffer
    at ServerResponse.end (_http_outgoing.js:739:13)
    at Command.callback (/home/noah/http_service/index.js:228:21)
    at normal_reply (/home/noah/http_service/node_modules/redis/index.js:726:21)
    at RedisClient.return_reply (/home/noah/http_service/node_modules/redis/index.js:824:9)
    at JavascriptRedisParser.returnReply (/home/noah/http_service/node_modules/redis/index.js:192:18)
    at JavascriptRedisParser.execute (/home/noah/http_service/node_modules/redis-parser/lib/parser.js:574:12)
    at Socket.<anonymous> (/home/noah/http_service/node_modules/redis/index.js:274:27)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)

该类型的细胞,表明这是一个字符串,所以我真的抓我的头,我的下一个步骤应该是什么。

redis node-redis
1个回答
0
投票

好了,结果还是不行字符串格式。所以,我在res.end使用JSON.stringify()()。我应该使用的结果将typeof()调用,而不是关键已。

© www.soinside.com 2019 - 2024. All rights reserved.