Skip to content

Commit 40f85aa

Browse files
committed
Add IPv6 and IPv4 tests
1 parent 890f60a commit 40f85aa

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,16 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
11831183

11841184
exports.createClient = function (port_arg, host_arg, options) {
11851185

1186+
var cnxFamily;
1187+
1188+
if (options && options.family) {
1189+
cnxFamily = (options.family == 'IPv6' ? 6 : 4);
1190+
}
1191+
11861192
var cnxOptions = {
11871193
'port' : port_arg || default_port,
11881194
'host' : host_arg || default_host,
1189-
'family' : options.family || 'IPv4'
1195+
'family' : cnxFamily || '4'
11901196
};
11911197

11921198
var redis_client, net_client;

test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,51 @@ next = function next(name) {
115115

116116
// Tests are run in the order they are defined, so FLUSHDB should always be first.
117117

118+
tests.IPV4 = function () {
119+
var ipv4Client = redis.createClient( PORT, "127.0.0.1", { "family" : "IPv4" } );
120+
121+
ipv4Client.once("ready", function start_tests() {
122+
console.log("Connected to " + ipv4Client.host + ":" + ipv4Client.port + ", Redis server version " + ipv4Client.server_info.redis_version + "\n");
123+
console.log("Using reply parser " + ipv4Client.reply_parser.name);
124+
125+
ipv4Client.quit();
126+
run_next_test();
127+
});
128+
129+
ipv4Client.on('end', function () {
130+
131+
});
132+
133+
// Exit immediately on connection failure, which triggers "exit", below, which fails the test
134+
ipv4Client.on("error", function (err) {
135+
console.error("client: " + err.stack);
136+
process.exit();
137+
});
138+
}
139+
140+
tests.IPV6 = function () {
141+
var ipv6Client = redis.createClient( PORT, "::1", { "family" : "IPv6" } );
142+
143+
ipv6Client.once("ready", function start_tests() {
144+
console.log("Connected to " + ipv6Client.host + ":" + ipv6Client.port + ", Redis server version " + ipv6Client.server_info.redis_version + "\n");
145+
console.log("Using reply parser " + ipv6Client.reply_parser.name);
146+
147+
ipv6Client.quit();
148+
run_next_test();
149+
});
150+
151+
ipv6Client.on('end', function () {
152+
153+
});
154+
155+
// Exit immediately on connection failure, which triggers "exit", below, which fails the test
156+
ipv6Client.on("error", function (err) {
157+
console.error("client: " + err.stack);
158+
process.exit();
159+
});
160+
}
161+
162+
118163
tests.FLUSHDB = function () {
119164
var name = "FLUSHDB";
120165
client.select(test_db_num, require_string("OK", name));

0 commit comments

Comments
 (0)