Failing to connect to hosted redis: Ready check fa

2019-07-14 07:36发布

问题:

I'm trying to connect to a hosted redis on IrisCouch that I provisioned via Nodejitsu.

What I think are the relevant parts of my server.js :

var redisUrl = require('url').parse(config.REDIS_CONNECTION_URI);
var client = require('redis').createClient(redisUrl.port, redisUrl.hostname);

I don't have any interaction with the client in my server.js yet, which is why I think it's weird that it's throwing the "operation not permitted", since basicly the only operation I do is to connect. I don't have a redis.conf file and I believe I shouldn't need one since I do not host the redis instance myself.

Log:

 Express server listening on port 3000

/Users/soroushhakami/dev/projects/projectx/node_modules/redis/index.js:504
                throw callback_err;
                      ^
Error: Ready check failed: ERR operation not permitted
    at RedisClient.on_info_cmd (/Users/soroushhakami/dev/projects/projectx/node_modules/redis/index.js:317:35)
    at Command.RedisClient.ready_check.send_anyway [as callback] (/Users/soroushhakami/dev/projects/projectx/node_modules/redis/index.js:365:14)
    at RedisClient.return_error (/Users/soroushhakami/dev/projects/projectx/node_modules/redis/index.js:500:25)
    at ReplyParser.RedisClient.init_parser (/Users/soroushhakami/dev/projects/projectx/node_modules/redis/index.js:260:14)
    at ReplyParser.EventEmitter.emit (events.js:96:17)
    at ReplyParser.send_error (/Users/soroushhakami/dev/projects/projectx/node_modules/redis/lib/parser/javascript.js:293:10)
    at ReplyParser.execute (/Users/soroushhakami/dev/projects/projectx/node_modules/redis/lib/parser/javascript.js:176:22)
    at RedisClient.on_data (/Users/soroushhakami/dev/projects/projectx/node_modules/redis/index.js:476:27)
    at Socket.<anonymous> (/Users/soroushhakami/dev/projects/projectx/node_modules/redis/index.js:79:14)
    at Socket.EventEmitter.emit (events.js:96:17)

Any ideas on what could be the problem?

回答1:

You need to call client.auth() directly after creating the client:

var client = require('redis').createClient(redisUrl.port, redisUrl.hostname);
client.auth(PASSWORD);

The confusing thing is that when you don't call .auth() on client but nothing else either, you will get a failed ready check error.



回答2:

I usually have that error while CLI-testing.

I guess the issue is that the call to auth should be made before the ready event is emitted (as robertklep mentions). When you're testing using the CLI the client starts connecting as soon as you hit the enter key at the end of your var client = redis.createClient(port, host); line and probably sends an IDLE command of some sort before you even get the chance to send the AUTH command, which triggers the ERR operation not permitted error.

tl;dr

when CLI-testing, create your redis client with the following code:

var redis = require('redis');
function createClient(port, host, pass) {
    var client = redis.createClient(port, host);
    client.auth(pass);
    return client;
}

var r = createClient(<MYPORT>, <MYHOST>, <MYPASS>);


标签: node.js redis