diff --git a/README.md b/README.md index 6e9301ca45..bd03d95cd7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/changelog.md b/changelog.md index a82bd6f51e..f90a46dc99 100644 --- a/changelog.md +++ b/changelog.md @@ -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. diff --git a/index.js b/index.js index 780fb78c8e..0af6eb8f45 100644 --- a/index.js +++ b/index.js @@ -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 { @@ -517,6 +525,10 @@ RedisClient.prototype.return_error = function (err) { 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") { diff --git a/package.json b/package.json index 2c57552f6c..dea4ba59d0 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name" : "redis", - "version" : "0.3.6", + "version" : "0.3.7", "description" : "Redis client library", "author": "Matt Ranney ", "contributors": [