You've already forked node-redis
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:
14
README.md
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,
|
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.
|
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"
|
### "end"
|
||||||
|
|
||||||
`client` will emit `end` when an established Redis server connection has closed.
|
`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)
|
## redis.createClient(port, host)
|
||||||
|
|
||||||
Create a new client connection. `port` defaults to `6379` and `host` defaults
|
Create a new client connection. `port` defaults to `6379` and `host` defaults
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
## v0.3.7 - November 9, 2010
|
||||||
|
|
||||||
|
Add "drain" and "idle" events.
|
||||||
|
|
||||||
## v0.3.6 - November 3, 2010
|
## v0.3.6 - November 3, 2010
|
||||||
|
|
||||||
Add all known Redis commands from Redis master, even ones that are coming in 2.2 and beyond.
|
Add all known Redis commands from Redis master, even ones that are coming in 2.2 and beyond.
|
||||||
|
12
index.js
12
index.js
@@ -435,6 +435,10 @@ function RedisClient(stream) {
|
|||||||
self.connection_gone("end");
|
self.connection_gone("end");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.stream.on("drain", function () {
|
||||||
|
self.emit("drain");
|
||||||
|
});
|
||||||
|
|
||||||
events.EventEmitter.call(this);
|
events.EventEmitter.call(this);
|
||||||
}
|
}
|
||||||
util.inherits(RedisClient, events.EventEmitter);
|
util.inherits(RedisClient, events.EventEmitter);
|
||||||
@@ -505,6 +509,10 @@ RedisClient.prototype.on_data = function (data) {
|
|||||||
RedisClient.prototype.return_error = function (err) {
|
RedisClient.prototype.return_error = function (err) {
|
||||||
var command_obj = this.command_queue.shift();
|
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") {
|
if (command_obj && typeof command_obj.callback === "function") {
|
||||||
command_obj.callback(err);
|
command_obj.callback(err);
|
||||||
} else {
|
} else {
|
||||||
@@ -517,6 +525,10 @@ RedisClient.prototype.return_error = function (err) {
|
|||||||
RedisClient.prototype.return_reply = function (reply) {
|
RedisClient.prototype.return_reply = function (reply) {
|
||||||
var command_obj = this.command_queue.shift(),
|
var command_obj = this.command_queue.shift(),
|
||||||
obj, i, len, key, val, type;
|
obj, i, len, key, val, type;
|
||||||
|
|
||||||
|
if (this.subscriptions === false && this.command_queue.length === 0) {
|
||||||
|
this.emit("idle");
|
||||||
|
}
|
||||||
|
|
||||||
if (command_obj) {
|
if (command_obj) {
|
||||||
if (typeof command_obj.callback === "function") {
|
if (typeof command_obj.callback === "function") {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
{ "name" : "redis",
|
{ "name" : "redis",
|
||||||
"version" : "0.3.6",
|
"version" : "0.3.7",
|
||||||
"description" : "Redis client library",
|
"description" : "Redis client library",
|
||||||
"author": "Matt Ranney <mjr@ranney.com>",
|
"author": "Matt Ranney <mjr@ranney.com>",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
|
Reference in New Issue
Block a user