Maison > Questions et réponses > le corps du texte
log
Error: Redis connection to redis:6379 failed - connect ECONNREFUSED 221.179.46.194:6379
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
ping
/ # ping mysql
PING mysql (172.19.0.2): 56 data bytes
64 bytes from 172.19.0.2: seq=0 ttl=64 time=0.101 ms
64 bytes from 172.19.0.2: seq=1 ttl=64 time=0.097 ms
64 bytes from 172.19.0.2: seq=2 ttl=64 time=0.100 ms
^C
--- mysql ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.097/0.099/0.101 ms
/ # ping redis
PING redis (172.19.0.3): 56 data bytes
64 bytes from 172.19.0.3: seq=0 ttl=64 time=0.069 ms
64 bytes from 172.19.0.3: seq=1 ttl=64 time=0.134 ms
64 bytes from 172.19.0.3: seq=2 ttl=64 time=0.112 ms
^C
--- redis ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.069/0.105/0.134 ms
/ #
docker-compose
redis:
image: redis
what:
image: daocloud.io/who/what
restart: always
depends_on:
- mysql
- redis
PHPz2017-04-17 16:20:12
找到原因了
这里变动了hostname要另外注入 https://github.com/mcollina/m...server.js
原本的写法
persistence: {
factory: mosca.persistence.Redis,
url: config.redis.host.concat(':').concat(config.redis.port) // 拼接出来不合法的参数redis:6379
}
更正
persistence: {
factory: mosca.persistence.Redis,
host: 'your redis host',
port: 'your redis port'
}
persistance的构造方法lib/persistence/redis.js
var Redis = require("ioredis");
RedisPersistence.prototype._buildClient = function() {
var options = this.options.redisOptions || {};
if (this.options.host) {
options.host = this.options.host;
}
if (this.options.port) {
options.port = this.options.port;
}
if (this.options.db) {
options.db = this.options.db;
}
if (this.options.password) {
options.password = this.options.password;
}
return new Redis(options);
};
这是一个ioredis的API,参考 https://github.com/luin/iored...
仅仅支持以下参数,并不支持url参数
var redisOnPort6380 = new Redis(6380);
var anotherRedis = new Redis(6380, '192.168.100.1');
var unixSocketRedis = new Redis({ path: '/tmp/echo.sock' });
var unixSocketRedis2 = new Redis('/tmp/echo.sock');
var urlRedis = new Redis('redis://user:password@redis-service.com:6379/');
var urlRedis2 = new Redis('//localhost:6379');
var authedRedis = new Redis(6380, '192.168.100.1', { password: 'password' });
就是不知道为什么连接出错不会报错???一直重试到,直接内存爆炸。