You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Add IPv6 and IPv4 tests
This commit is contained in:
8
index.js
8
index.js
@@ -1183,10 +1183,16 @@ RedisClient.prototype.eval = RedisClient.prototype.EVAL = function () {
|
|||||||
|
|
||||||
exports.createClient = function (port_arg, host_arg, options) {
|
exports.createClient = function (port_arg, host_arg, options) {
|
||||||
|
|
||||||
|
var cnxFamily;
|
||||||
|
|
||||||
|
if (options && options.family) {
|
||||||
|
cnxFamily = (options.family == 'IPv6' ? 6 : 4);
|
||||||
|
}
|
||||||
|
|
||||||
var cnxOptions = {
|
var cnxOptions = {
|
||||||
'port' : port_arg || default_port,
|
'port' : port_arg || default_port,
|
||||||
'host' : host_arg || default_host,
|
'host' : host_arg || default_host,
|
||||||
'family' : options.family || 'IPv4'
|
'family' : cnxFamily || '4'
|
||||||
};
|
};
|
||||||
|
|
||||||
var redis_client, net_client;
|
var redis_client, net_client;
|
||||||
|
45
test.js
45
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 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));
|
||||||
|
Reference in New Issue
Block a user