【问题标题】:Why am I getting this hgetall type error?为什么我会收到此 hgetall 类型错误?
【发布时间】:2019-02-07 04:32:47
【问题描述】:

这里是有问题的代码:

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)

typeof 调用显示它是一个字符串,所以我真的为下一步应该做什么而摸不着头脑。

【问题讨论】:

    标签: redis node-redis


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      相关资源
      最近更新 更多