Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 467
amehta Avatar asked Feb 24 '23 13:02

amehta


1 Answers

Try

console.log(messages.toString());
like image 145
Eldar Djafarov Avatar answered Feb 26 '23 22:02

Eldar Djafarov