Browse Source

Add "drain" and "idle" events.

gh-pages v0.3.7
Matt Ranney 14 years ago
parent
commit
1eb3f6a1aa
  1. 14
      README.md
  2. 4
      changelog.md
  3. 12
      index.js
  4. 2
      package.json

14
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

4
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.

12
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") {

2
package.json

@ -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": [

Loading…
Cancel
Save