You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
improve the interface to better support unix socket.
delete client.host delete client.port add client.address add client.connectionOptions add tests.UNIX_SOCKET update all error message to use client.address update retry connection
This commit is contained in:
46
test.js
46
test.js
@@ -119,7 +119,7 @@ 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("Connected to " + ipv4Client.address + ", Redis server version " + ipv4Client.server_info.redis_version + "\n");
|
||||
console.log("Using reply parser " + ipv4Client.reply_parser.name);
|
||||
|
||||
ipv4Client.quit();
|
||||
@@ -141,7 +141,7 @@ 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("Connected to " + ipv6Client.address + ", Redis server version " + ipv6Client.server_info.redis_version + "\n");
|
||||
console.log("Using reply parser " + ipv6Client.reply_parser.name);
|
||||
|
||||
ipv6Client.quit();
|
||||
@@ -159,6 +159,31 @@ tests.IPV6 = function () {
|
||||
});
|
||||
}
|
||||
|
||||
tests.UNIX_SOCKET = function () {
|
||||
var unixClient = redis.createClient('/tmp/redis.sock');
|
||||
|
||||
// if this fails, check the permission of unix socket.
|
||||
// unixsocket /tmp/redis.sock
|
||||
// unixsocketperm 777
|
||||
|
||||
unixClient.once('ready', function start_tests(){
|
||||
console.log("Connected to " + unixClient.address + ", Redis server version " + unixClient.server_info.redis_version + "\n");
|
||||
console.log("Using reply parser " + unixClient.reply_parser.name);
|
||||
|
||||
unixClient.quit();
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
unixClient.on( 'end', function(){
|
||||
|
||||
});
|
||||
|
||||
// Exit immediately on connection failure, which triggers "exit", below, which fails the test
|
||||
unixClient.on("error", function (err) {
|
||||
console.error("client: " + err.stack);
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
|
||||
tests.FLUSHDB = function () {
|
||||
var name = "FLUSHDB";
|
||||
@@ -610,11 +635,16 @@ tests.CLIENT_LIST = function() {
|
||||
return next(name);
|
||||
}
|
||||
|
||||
var pattern = /^add=/;
|
||||
if ( server_version_at_least(client, [2, 8, 12])) {
|
||||
pattern = /^id=\d+ addr=/;
|
||||
}
|
||||
|
||||
function checkResult(result) {
|
||||
var lines = result.toString().split('\n').slice(0, -1);
|
||||
assert.strictEqual(lines.length, 4);
|
||||
assert(lines.every(function(line) {
|
||||
return line.match(/^addr=/);
|
||||
return line.match(pattern);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -683,7 +713,7 @@ tests.WATCH_TRANSACTION = function () {
|
||||
|
||||
|
||||
tests.detect_buffers = function () {
|
||||
var name = "detect_buffers", detect_client = redis.createClient(null, null, {detect_buffers: true});
|
||||
var name = "detect_buffers", detect_client = redis.createClient({detect_buffers: true});
|
||||
|
||||
detect_client.on("ready", function () {
|
||||
// single Buffer or String
|
||||
@@ -750,9 +780,9 @@ tests.detect_buffers = function () {
|
||||
tests.socket_nodelay = function () {
|
||||
var name = "socket_nodelay", c1, c2, c3, ready_count = 0, quit_count = 0;
|
||||
|
||||
c1 = redis.createClient(null, null, {socket_nodelay: true});
|
||||
c2 = redis.createClient(null, null, {socket_nodelay: false});
|
||||
c3 = redis.createClient(null, null);
|
||||
c1 = redis.createClient({socket_nodelay: true});
|
||||
c2 = redis.createClient({socket_nodelay: false});
|
||||
c3 = redis.createClient();
|
||||
|
||||
function quit_check() {
|
||||
quit_count++;
|
||||
@@ -2194,7 +2224,7 @@ run_next_test = function run_next_test() {
|
||||
};
|
||||
|
||||
client.once("ready", function start_tests() {
|
||||
console.log("Connected to " + client.host + ":" + client.port + ", Redis server version " + client.server_info.redis_version + "\n");
|
||||
console.log("Connected to " + client.address + ", Redis server version " + client.server_info.redis_version + "\n");
|
||||
console.log("Using reply parser " + client.reply_parser.name);
|
||||
|
||||
run_next_test();
|
||||
|
Reference in New Issue
Block a user