1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Add "drain" and "idle" events.

This commit is contained in:
Matt Ranney
2010-11-09 13:13:40 -08:00
parent e6f7dc5f20
commit 1eb3f6a1aa
4 changed files with 31 additions and 1 deletions

View File

@@ -111,10 +111,24 @@ cryptic error messages like this:
Not very useful in diagnosing the problem, but if your program isn't ready to handle this,
it is probably the right thing to just exit.
`client` will also emit `error` if an exception is thrown inside of `node_redis` for whatever reason.
In the future, there will be a better way to distinguish these error types.
### "end"
`client` will emit `end` when an established Redis server connection has closed.
### "drain"
`client` will emit `drain` when the TCP connection to the Redis server has been buffering, but is now
writable. This event can be used to stream commands in to Redis and adapt to backpressure. Right now,
you need to check `client.command_queue.length` to decide when to reduce your send rate. Then you can
resume sending when you get `drain`.
### "idle"
`client` will emit `idle` when there are no outstanding commands that are awaiting a response.
## redis.createClient(port, host)
Create a new client connection. `port` defaults to `6379` and `host` defaults

View File

@@ -1,6 +1,10 @@
Changelog
=========
## v0.3.7 - November 9, 2010
Add "drain" and "idle" events.
## v0.3.6 - November 3, 2010
Add all known Redis commands from Redis master, even ones that are coming in 2.2 and beyond.

View File

@@ -435,6 +435,10 @@ function RedisClient(stream) {
self.connection_gone("end");
});
this.stream.on("drain", function () {
self.emit("drain");
});
events.EventEmitter.call(this);
}
util.inherits(RedisClient, events.EventEmitter);
@@ -505,6 +509,10 @@ RedisClient.prototype.on_data = function (data) {
RedisClient.prototype.return_error = function (err) {
var command_obj = this.command_queue.shift();
if (this.subscriptions === false && this.command_queue.length === 0) {
this.emit("idle");
}
if (command_obj && typeof command_obj.callback === "function") {
command_obj.callback(err);
} else {
@@ -518,6 +526,10 @@ RedisClient.prototype.return_reply = function (reply) {
var command_obj = this.command_queue.shift(),
obj, i, len, key, val, type;
if (this.subscriptions === false && this.command_queue.length === 0) {
this.emit("idle");
}
if (command_obj) {
if (typeof command_obj.callback === "function") {
// HGETALL special case replies with keyed Buffers

View File

@@ -1,5 +1,5 @@
{ "name" : "redis",
"version" : "0.3.6",
"version" : "0.3.7",
"description" : "Redis client library",
"author": "Matt Ranney <mjr@ranney.com>",
"contributors": [