From 5afa763c89d01f37bd7894a2aaf1f8d411710ce5 Mon Sep 17 00:00:00 2001 From: David Trejo Date: Mon, 5 Mar 2012 15:31:43 -0500 Subject: [PATCH 1/3] readme code formatting --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 10b90cfced..40d60a81c9 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,7 @@ be loading the database from disk. While loading, the server not respond to any indicates whether the server is ready for more commands. When ready, `node_redis` emits a `ready` event. Setting `no_ready_check` to `true` will inhibit this check. - +```js var redis = require("redis"), client = redis.createClient(null, null, {detect_buffers: true}); @@ -202,6 +202,7 @@ Setting `no_ready_check` to `true` will inhibit this check. console.log(reply.toString()); // Will print `` }); client.end(); +``` `createClient()` returns a `RedisClient` object that is named `client` in all of the examples here. From 234ae6be9a80924552062ea2160e8ad2be62dea7 Mon Sep 17 00:00:00 2001 From: David Trejo Date: Mon, 5 Mar 2012 17:25:32 -0500 Subject: [PATCH 2/3] Emit Error objects not strings --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5c7799a8f8..eb27628b97 100644 --- a/index.js +++ b/index.js @@ -160,11 +160,11 @@ RedisClient.prototype.do_auth = function () { }, 2000); // TODO - magic number alert return; } else { - return self.emit("error", "Auth error: " + err); + return self.emit("error", new Error("Auth error: " + err.message)); } } if (res.toString() !== "OK") { - return self.emit("error", "Auth failed: " + res.toString()); + return self.emit("error", new Error("Auth failed: " + res.toString())); } if (exports.debug_mode) { console.log("Auth succeeded " + self.host + ":" + self.port + " id " + self.connection_id); @@ -290,7 +290,7 @@ RedisClient.prototype.on_info_cmd = function (err, res) { var self = this, obj = {}, lines, retry_time; if (err) { - return self.emit("error", "Ready check failed: " + err); + return self.emit("error", new Error("Ready check failed: " + err.message)); } lines = res.toString().split("\r\n"); From cd5db44f665ff50d2fcd7346de2f561fffa80ef1 Mon Sep 17 00:00:00 2001 From: David Trejo Date: Mon, 5 Mar 2012 17:31:47 -0500 Subject: [PATCH 3/3] readme: how to correctly auth to server, what error looks like if done wrong --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 40d60a81c9..c0d23bd915 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,9 @@ first command after connecting. This can be tricky to coordinate with reconnect etc. To make this easier, `client.auth()` stashes `password` and will send it after each connection, including reconnections. `callback` is invoked only once, after the response to the very first `AUTH` command sent. +NOTE: Your call to `client.auth()` should not be inside the ready handler. If +you are doing this wrong, `client` will emit an error that looks +something like this `Error: Ready check failed: ERR operation not permitted`. ## client.end()