开发者

Converting Buffer to String on a Redis Get in a Node.js Heroku app

开发者 https://www.devze.com 2023-03-20 19:30 出处:网络
This is my very basic GET function app.get(\'/\', function(request, response) { response.contentType(\'application/json\');

This is my very basic GET function

app.get('/', function(request, response) {
  response.contentType('application/json');
  var lid = request.param("lid");
  client.llen(lid, function(reply, len){
      client.lrange(lid, 0, len-1, function(reply, messages){
      console.log(messages);
      response.send(messages);
    })
  });
});

For some reason, the console output and the response i get looks like

[ <Buffer 5b 7b 22 6c 61 77 79 65 72 5f .开发者_运维问答.. 61 64 61 74 61 22 3a 22 36 22 7d 5d> ]

I'm storing these as JSON strings:

client.lpush(lid, JSON.stringify(to_store))

Any ideas why my response is not a JSON string??

Thank you.


Try

console.log(messages.toString());
0

精彩评论

暂无评论...
验证码 换一张
取 消