Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
node> redis.set("greeting", "Thank you, Brain, for building us redis-node-client")
node> redis.get("greeting", function(err, reply) { sys.puts(reply); })
node> Thank you, Brain, for building us redis-node-client
redis.get("greeting", function(err, reply) { sys.puts(typeof(reply)); })
node> object // oops, it's an object instead of string
redis.get("greeting", function(err, reply) { sys.puts(sys.inspect(reply)); })
// What's this? a buffer representation?
node> { '0': 84, '1': 104, '2': 97, '3': 110 ... , length: 51 }
@juvenn

This comment has been minimized.

Show comment Hide comment
@juvenn

juvenn May 8, 2010

What kind of object is the reply? It must have an toString method, so sys.puts could print the string; but why == comparison will be true, but === will be false? I'd expect == comparison will be false as well. And the inspected result seems it's ASCII encoded.

So we should first hard convert the reply to string, before we handle this string, right?

Thanks!

Owner

juvenn commented May 8, 2010

What kind of object is the reply? It must have an toString method, so sys.puts could print the string; but why == comparison will be true, but === will be false? I'd expect == comparison will be false as well. And the inspected result seems it's ASCII encoded.

So we should first hard convert the reply to string, before we handle this string, right?

Thanks!

@fictorial

This comment has been minimized.

Show comment Hide comment
@fictorial

fictorial May 8, 2010

Buffer, for binary compatibility.

Buffer, for binary compatibility.

@juvenn

This comment has been minimized.

Show comment Hide comment
@juvenn

juvenn May 9, 2010

I see, thanks for confirming!

node.js api has documented buffer.toString(), my ignorance:

http://nodejs.org/api.html#buffers-3

Owner

juvenn commented May 9, 2010

I see, thanks for confirming!

node.js api has documented buffer.toString(), my ignorance:

http://nodejs.org/api.html#buffers-3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment