Skip to content

Commit

Permalink
Support for multiple response parsers and hiredis C library from Piet…
Browse files Browse the repository at this point in the history
…er Noordhuis.

Return Strings instead of Buffers by default.
Empty nested mb reply bug fix.
  • Loading branch information
mranney committed Dec 9, 2010
1 parent 36c40ee commit b81da6d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Install with:

npm install redis

By default, a pure JavaScript reply parser is used. This is clever and portable, but not as fast for large responses as `hiredis` from the
Redis distribution. To use the `hiredis`, do:
For portability, a pure JavaScript reply parser is used by default. Pieter Noordhuis has provided a binding to the
official `hiredis` C library, which is non-blocking and fast. To use `hiredis`, do:

npm install hiredis
npm install hiredis redis

If `hiredis` is installed, `node_redis` will use it by default.

Expand All @@ -20,7 +20,7 @@ If `hiredis` is installed, `node_redis` will use it by default.
number of sites.

`node_redis` was originally written to replace `node-redis-client` which hasn't been updated in a while, and no longer works
on recent versions of node.
with recent versions of node.


## Usage
Expand Down Expand Up @@ -116,7 +116,7 @@ Not very useful in diagnosing the problem, but if your program isn't ready to ha
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.
It would be nice to distinguish these two cases.

### "end"

Expand All @@ -133,12 +133,18 @@ resume sending when you get `drain`.

`client` will emit `idle` when there are no outstanding commands that are awaiting a response.

## redis.createClient(port, host)
## redis.createClient(port, host, options)

Create a new client connection. `port` defaults to `6379` and `host` defaults
to `127.0.0.1`. If you have Redis running on the same computer as node, then the defaults are probably fine.
to `127.0.0.1`. If you have `redis-server` running on the same computer as node, then the defaults for
port and host are probably fine. `options` in an object with the following possible properties:

`createClient` returns a `RedisClient` object that is named `client` in all of the examples here.
* `parser`: which Redis protocol reply parser to use. Defaults to `hiredis` if that module is installed.
This may also be set to `javascript`.
* `return_buffers`: defaults to false. If set to `true`, then bulk data replies will be returned as node Buffer
objects instead of JavaScript Strings.

`createClient()` returns a `RedisClient` object that is named `client` in all of the examples here.


## client.end()
Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Changelog

## v0.4.0 - December 5, 2010

Support for multiple response parsers and hiredis.
Support for multiple response parsers and hiredis C library from Pieter Noordhuis.
Return Strings instead of Buffers by default.
Empty nested mb reply bug fix.

## v0.3.9 - November 30, 2010

Expand Down
13 changes: 7 additions & 6 deletions multi_bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ var redis = require("./index"),
num_clients = parseInt(process.argv[2]) || 50,
active_clients = 0,
clients = new Array(num_clients),
num_requests = 20000,
num_requests = 2000,
issued_requests = 0,
latency = new Array(num_requests),
tests = [],
test_start;
test_start,
client_options = {
parser: "javascript",
return_buffers: false
};

redis.debug_mode = false;

Expand Down Expand Up @@ -54,10 +58,7 @@ function create_clients(callback) {
var client, connected = active_clients;

while (active_clients < num_clients) {
client = clients[active_clients++] = redis.createClient(6379, "127.0.0.1", {
parser: "hiredis",
return_buffers: false
});
client = clients[active_clients++] = redis.createClient(6379, "127.0.0.1", client_options);
client.on("connect", function() {
// Fire callback when all clients are connected
connected += 1;
Expand Down

0 comments on commit b81da6d

Please sign in to comment.