From b81da6d8fc34e8afa80c3ec4f865c5497f3baca9 Mon Sep 17 00:00:00 2001 From: Matt Ranney Date: Wed, 8 Dec 2010 16:15:45 -0800 Subject: [PATCH] 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. --- README.md | 22 ++++++++++++++-------- changelog.md | 3 ++- multi_bench.js | 13 +++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2833163676..07978514e8 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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" @@ -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() diff --git a/changelog.md b/changelog.md index 22a99ce4e5..070932b61b 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/multi_bench.js b/multi_bench.js index 2ad39bfab1..1128554485 100644 --- a/multi_bench.js +++ b/multi_bench.js @@ -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; @@ -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;