1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

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.
This commit is contained in:
Matt Ranney
2010-12-08 16:15:45 -08:00
parent 36c40ee03d
commit b81da6d8fc
3 changed files with 23 additions and 15 deletions

View File

@@ -7,10 +7,10 @@ Install with:
npm install redis 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 For portability, a pure JavaScript reply parser is used by default. Pieter Noordhuis has provided a binding to the
Redis distribution. To use the `hiredis`, do: 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. 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. 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 `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 ## 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. 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. `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" ### "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. `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 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() ## client.end()

View File

@@ -3,8 +3,9 @@ Changelog
## v0.4.0 - December 5, 2010 ## 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. Return Strings instead of Buffers by default.
Empty nested mb reply bug fix.
## v0.3.9 - November 30, 2010 ## v0.3.9 - November 30, 2010

View File

@@ -2,11 +2,15 @@ var redis = require("./index"),
num_clients = parseInt(process.argv[2]) || 50, num_clients = parseInt(process.argv[2]) || 50,
active_clients = 0, active_clients = 0,
clients = new Array(num_clients), clients = new Array(num_clients),
num_requests = 20000, num_requests = 2000,
issued_requests = 0, issued_requests = 0,
latency = new Array(num_requests), latency = new Array(num_requests),
tests = [], tests = [],
test_start; test_start,
client_options = {
parser: "javascript",
return_buffers: false
};
redis.debug_mode = false; redis.debug_mode = false;
@@ -54,10 +58,7 @@ function create_clients(callback) {
var client, connected = active_clients; var client, connected = active_clients;
while (active_clients < num_clients) { while (active_clients < num_clients) {
client = clients[active_clients++] = redis.createClient(6379, "127.0.0.1", { client = clients[active_clients++] = redis.createClient(6379, "127.0.0.1", client_options);
parser: "hiredis",
return_buffers: false
});
client.on("connect", function() { client.on("connect", function() {
// Fire callback when all clients are connected // Fire callback when all clients are connected
connected += 1; connected += 1;