1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Merge branch 'master' of https://github.com/migounette/node_redis into migounette-master

This commit is contained in:
Bryce Baril
2014-07-10 22:01:34 -07:00
3 changed files with 64 additions and 6 deletions

View File

@@ -211,6 +211,8 @@ limits total time for client to reconnect. Value is provided in milliseconds and
* `max_attempts` defaults to `null`. By default client will try reconnecting until connected. Setting `max_attempts` * `max_attempts` defaults to `null`. By default client will try reconnecting until connected. Setting `max_attempts`
limits total amount of reconnects. limits total amount of reconnects.
* `auth_pass` defaults to `null`. By default client will try connecting without auth. If set, client will run redis auth command on connect. * `auth_pass` defaults to `null`. By default client will try connecting without auth. If set, client will run redis auth command on connect.
* `family` defaults to `IPv4`. The client connects in IPv4 if not specified or if the DNS resolution returns an IPv4 address.
You can force an IPv6 if you set the family to 'IPv6'. See nodejs net or dns modules how to use the family type.
```js ```js
var redis = require("redis"), var redis = require("redis"),

View File

@@ -1214,16 +1214,27 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
exports.createClient = function (port_arg, host_arg, options) { exports.createClient = function (port_arg, host_arg, options) {
var port = port_arg || default_port,
host = host_arg || default_host,
redis_client, net_client;
net_client = net.createConnection(port, host); var cnxFamily;
if (options && options.family) {
cnxFamily = (options.family == 'IPv6' ? 6 : 4);
}
var cnxOptions = {
'port' : port_arg || default_port,
'host' : host_arg || default_host,
'family' : cnxFamily || '4'
};
var redis_client, net_client;
net_client = net.createConnection(cnxOptions);
redis_client = new RedisClient(net_client, options); redis_client = new RedisClient(net_client, options);
redis_client.port = port; redis_client.port = cnxOptions.port;
redis_client.host = host; redis_client.host = cnxOptions.host;
return redis_client; return redis_client;
}; };

45
test.js
View File

@@ -115,6 +115,51 @@ next = function next(name) {
// Tests are run in the order they are defined, so FLUSHDB should always be first. // Tests are run in the order they are defined, so FLUSHDB should always be first.
tests.IPV4 = function () {
var ipv4Client = redis.createClient( PORT, "127.0.0.1", { "family" : "IPv4" } );
ipv4Client.once("ready", function start_tests() {
console.log("Connected to " + ipv4Client.host + ":" + ipv4Client.port + ", Redis server version " + ipv4Client.server_info.redis_version + "\n");
console.log("Using reply parser " + ipv4Client.reply_parser.name);
ipv4Client.quit();
run_next_test();
});
ipv4Client.on('end', function () {
});
// Exit immediately on connection failure, which triggers "exit", below, which fails the test
ipv4Client.on("error", function (err) {
console.error("client: " + err.stack);
process.exit();
});
}
tests.IPV6 = function () {
var ipv6Client = redis.createClient( PORT, "::1", { "family" : "IPv6" } );
ipv6Client.once("ready", function start_tests() {
console.log("Connected to " + ipv6Client.host + ":" + ipv6Client.port + ", Redis server version " + ipv6Client.server_info.redis_version + "\n");
console.log("Using reply parser " + ipv6Client.reply_parser.name);
ipv6Client.quit();
run_next_test();
});
ipv6Client.on('end', function () {
});
// Exit immediately on connection failure, which triggers "exit", below, which fails the test
ipv6Client.on("error", function (err) {
console.error("client: " + err.stack);
process.exit();
});
}
tests.FLUSHDB = function () { tests.FLUSHDB = function () {
var name = "FLUSHDB"; var name = "FLUSHDB";
client.select(test_db_num, require_string("OK", name)); client.select(test_db_num, require_string("OK", name));