From 9c68a286b1b0be913bbbca112ea4d241eda96d91 Mon Sep 17 00:00:00 2001 From: migounette Date: Mon, 23 Jun 2014 16:38:37 +0200 Subject: [PATCH 1/4] Add full IPv6 redis connection capability in a full IPv6 network or in a mix network (IPv4 and IPv6) --- README.md | 1 + changelog.md | 7 +++++++ index.js | 17 +++++++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d8bd75ae32..b837bb99cb 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,7 @@ 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` 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. +* `family` defaults to `IPv4`. By default client will try connecting with a IPv4 DNS resolution when a FQDN host is set. You can also specify and IPv6 for forcing a IPv6 FQDN resolution. ```js var redis = require("redis"), diff --git a/changelog.md b/changelog.md index e0ae48c92a..74aa941e09 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,13 @@ Changelog ========= +## v0.10.4 - Jun 23, 2014 + +* Add redis-cli createClient(port, host, options) full IPv6 Network capability + Specify the family type IPv4 or IPv6 in the options object. + + eg: { 'family' : 'IPv6' } + ## v0.10.3 - May 22, 2014 * Update command list to match Redis 2.8.9 (Charles Feng) diff --git a/index.js b/index.js index 13964983e0..f4e0095c0e 100644 --- a/index.js +++ b/index.js @@ -1182,16 +1182,21 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () { 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 cnxOptions = { + 'port' : port_arg || default_port, + 'host' : host_arg || default_host, + 'family' : options.family || 'IPv4' + }; + + var redis_client, net_client; + + net_client = net.createConnection(cnxOptions); redis_client = new RedisClient(net_client, options); - redis_client.port = port; - redis_client.host = host; + redis_client.port = cnxOptions.port; + redis_client.host = cnxOptions.host; return redis_client; }; From 890f60ac572d2675db5ab014619a31e91a7cca2a Mon Sep 17 00:00:00 2001 From: migounette Date: Mon, 23 Jun 2014 16:40:40 +0200 Subject: [PATCH 2/4] change the version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1e408a2b12..bb9e78962c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redis", - "version": "0.10.3", + "version": "0.10.4", "description": "Redis client library", "keywords": [ "redis", From 40f85aa42ac2600b90bc99c517934a8e198313b2 Mon Sep 17 00:00:00 2001 From: migounette Date: Wed, 9 Jul 2014 10:39:08 +0200 Subject: [PATCH 3/4] Add IPv6 and IPv4 tests --- index.js | 8 +++++++- test.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f4e0095c0e..3b16d08e32 100644 --- a/index.js +++ b/index.js @@ -1183,10 +1183,16 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () { exports.createClient = function (port_arg, host_arg, options) { + 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' : options.family || 'IPv4' + 'family' : cnxFamily || '4' }; var redis_client, net_client; diff --git a/test.js b/test.js index ffbc54d1a8..13c039bdcb 100644 --- a/test.js +++ b/test.js @@ -115,6 +115,51 @@ next = function next(name) { // 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 () { var name = "FLUSHDB"; client.select(test_db_num, require_string("OK", name)); From 8e0dcc0a5599827d631e4cefc5c951843027ff75 Mon Sep 17 00:00:00 2001 From: migounette Date: Fri, 11 Jul 2014 04:49:50 +0200 Subject: [PATCH 4/4] Rollback package.json version and changelog.md Adjust the README.md section --- README.md | 3 ++- changelog.md | 7 ------- package.json | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b837bb99cb..d01cfc34d0 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,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` 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. -* `family` defaults to `IPv4`. By default client will try connecting with a IPv4 DNS resolution when a FQDN host is set. You can also specify and IPv6 for forcing a IPv6 FQDN resolution. +* `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 var redis = require("redis"), diff --git a/changelog.md b/changelog.md index 74aa941e09..e0ae48c92a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,13 +1,6 @@ Changelog ========= -## v0.10.4 - Jun 23, 2014 - -* Add redis-cli createClient(port, host, options) full IPv6 Network capability - Specify the family type IPv4 or IPv6 in the options object. - - eg: { 'family' : 'IPv6' } - ## v0.10.3 - May 22, 2014 * Update command list to match Redis 2.8.9 (Charles Feng) diff --git a/package.json b/package.json index bb9e78962c..1e408a2b12 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redis", - "version": "0.10.4", + "version": "0.10.3", "description": "Redis client library", "keywords": [ "redis",