You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-10 11:43:01 +03:00
Merge pull request #183 from DTrejo/master
How to correctly auth to server; what error to look for if you're doing it wrong; emit Error objects not string
This commit is contained in:
@@ -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.
|
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.
|
Setting `no_ready_check` to `true` will inhibit this check.
|
||||||
|
|
||||||
|
```js
|
||||||
var redis = require("redis"),
|
var redis = require("redis"),
|
||||||
client = redis.createClient(null, null, {detect_buffers: true});
|
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 `<Buffer 4f 4b>`
|
console.log(reply.toString()); // Will print `<Buffer 4f 4b>`
|
||||||
});
|
});
|
||||||
client.end();
|
client.end();
|
||||||
|
```
|
||||||
|
|
||||||
`createClient()` returns a `RedisClient` object that is named `client` in all of the examples here.
|
`createClient()` returns a `RedisClient` object that is named `client` in all of the examples here.
|
||||||
|
|
||||||
@@ -212,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,
|
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
|
including reconnections. `callback` is invoked only once, after the response to the very first
|
||||||
`AUTH` command sent.
|
`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()
|
## client.end()
|
||||||
|
|
||||||
|
6
index.js
6
index.js
@@ -160,11 +160,11 @@ RedisClient.prototype.do_auth = function () {
|
|||||||
}, 2000); // TODO - magic number alert
|
}, 2000); // TODO - magic number alert
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
return self.emit("error", "Auth error: " + err);
|
return self.emit("error", new Error("Auth error: " + err.message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (res.toString() !== "OK") {
|
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) {
|
if (exports.debug_mode) {
|
||||||
console.log("Auth succeeded " + self.host + ":" + self.port + " id " + self.connection_id);
|
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;
|
var self = this, obj = {}, lines, retry_time;
|
||||||
|
|
||||||
if (err) {
|
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");
|
lines = res.toString().split("\r\n");
|
||||||
|
Reference in New Issue
Block a user