redback.use() throws Redis connection to 127.0.0.1:[object Object] failed - EAFNOSUPPORT, Address family not supported by protocol family
adamvr opened this issue · comments
Hi!
This code:
var redis = require('redis'),
redback = require('redback'),
rc = redis.createClient();
console.log(rc instanceof redis.RedisClient); // True
redback.use(rc);
throws this:
Error: Redis connection to 127.0.0.1:[object Object] failed - EAFNOSUPPORT, Address family not supported by protocol family
at Socket.<anonymous> (/usr/local/lib/node_modules/redback/node_modules/redis/index.js:123:28)
at Socket.emit (events.js:64:17)
at Array.<anonymous> (net.js:836:27)
at EventEmitter._tickCallback (node.js:126:26)
It appears to be a problem with the Redback constructor:
this.client = arguments[0] instanceof redis.RedisClient ?
arguments[0] : redis.createClient.apply(this, arguments);
where arguments[0] instanceof redis.RedisClient does not return true.
This occurs using node_redis 0.6.7, redback 0.2.7 and node 0.4.11.
Cheers,
Adam
Sorry for the delay in getting back to you. I can't reproduce this bug - the following outputs bar as expected:
var redis = require('redis'),
redback = require('redback'),
rc = redis.createClient();
redback.use(rc);
redback = redback.createClient();
var foo = redback.createHash('test_hash');
foo.set('foo', 'bar', function (err) {
foo.get('foo', function (err, foo) {
console.log(foo); //bar
});
});
Pretty sure this happens when redis is installed both on the top-level module and in the redback module. Basically "require('redis')" is returning two different objects because of the way that node.js module caching works. Therefore, the prototypes of both are defined the same way but are not equal.
require('redis')
will return the same object if called twice, but redis.createClient()
won't. I added redback.use()
so that you could bind your own client - still not sure what's going on here
Not sure what happened, but updating everything seems to have fixed it. Cheers!