Permalink
Browse files

Add "drain" and "idle" events.

  • Loading branch information...
1 parent e6f7dc5 commit 1eb3f6a1aaf4c92b0042042cc9daebcb24078ae1 @mranney mranney committed Nov 9, 2010
Showing with 31 additions and 1 deletion.
  1. +14 −0 README.md
  2. +4 −0 changelog.md
  3. +12 −0 index.js
  4. +1 −1 package.json
View
@@ -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
@@ -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
@@ -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") {
View
@@ -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": [

0 comments on commit 1eb3f6a

Please sign in to comment.