Upgrade generic-pool to ~2.0.2

This commit is contained in:
Sandro Santilli 2013-03-14 11:58:30 +01:00
parent 5fa19a0515
commit 6c0d7813f6
7 changed files with 22 additions and 23 deletions

View File

@ -37,15 +37,15 @@ module.exports = (function() {
Step(
function() {
var step = this;
RedisPool.acquire(db, function(_redisClient) {
RedisPool.acquire(db, function(err, _redisClient) {
if ( err ) { step(err); return };
redisClient = _redisClient;
redisArgs.push(step);
redisClient[redisFunc.toUpperCase()].apply(redisClient, redisArgs);
});
},
function releaseRedisClient(err, data) {
if (err) throw err;
RedisPool.release(db, redisClient);
if ( redisClient ) RedisPool.release(db, redisClient);
callback(err, data);
}
);

View File

@ -59,13 +59,13 @@ module.exports = function() {
function getRedisClient() {
RedisPool.acquire(that.metadata_database, this);
},
function lookupMetadata(data) {
function lookupMetadata(err, data) {
if (err) throw err;
redisClient = data;
redisClient.HGET(redisKey, hashKey, this);
},
function releaseRedisClient(err, data) {
if (err) throw err;
RedisPool.release(that.metadata_database, redisClient);
if ( redisClient ) RedisPool.release(that.metadata_database, redisClient);
callback(err, data);
}
);

View File

@ -130,11 +130,12 @@ var oAuth = function(){
me.getOAuthHash = function(access_key, callback){
var that = this;
RedisPool.acquire(this.oauth_database, function(client){
RedisPool.acquire(this.oauth_database, function(err, client){
if ( err ) { callback(err); return; }
var redisClient = client;
redisClient.HGETALL(_.template(that.oauth_user_key, {oauth_access_key: access_key}), function(err, data){
RedisPool.release(that.oauth_database, redisClient);
return callback(err, data)
callback(err, data);
});
});
};

View File

@ -11,8 +11,8 @@ var RedisPool = {
if (!this.pools[database]) {
this.pools[database] = this.makePool(database);
}
this.pools[database].acquire(function(resource) {
callback(resource);
this.pools[database].acquire(function(err, resource) {
callback(err, resource);
});
},

9
npm-shrinkwrap.json generated
View File

@ -186,15 +186,10 @@
},
"pg": {
"version": "0.12.3-cdb1",
"from": "git://github.com/CartoDB/node-postgres.git#cdb_production",
"dependencies": {
"generic-pool": {
"version": "2.0.2"
}
}
"from": "git://github.com/CartoDB/node-postgres.git#cdb_production"
},
"generic-pool": {
"version": "1.0.12"
"version": "2.0.3"
},
"redis": {
"version": "0.7.1"

View File

@ -15,7 +15,7 @@
"underscore.string": "1.1.5",
"pg": "git://github.com/CartoDB/node-postgres.git#cdb_production",
"express": "~2.5.11",
"generic-pool": "1.0.x",
"generic-pool": "~2.0.2",
"redis": "0.7.1",
"hiredis": "*",
"step": "0.0.x",

View File

@ -18,7 +18,8 @@ test('test pool object has an aquire function', function(){
});
test('test calling aquire returns a redis client object that can get/set', function(done){
redis_pool.acquire(0, function(client){
redis_pool.acquire(0, function(err, client){
assert.ok(!err);
client.set("key","value");
client.get("key", function(err,data){
assert.equal(data, "value");
@ -29,12 +30,14 @@ test('test calling aquire returns a redis client object that can get/set', funct
});
test('test calling aquire on another DB returns a redis client object that can get/set', function(done){
redis_pool.acquire("MYDATABASE", function(client){
redis_pool.acquire("MYDATABASE", function(err, client){
assert.ok(!err);
client.set("key","value");
client.get("key", function(err,data){
assert.equal(data, "value");
redis_pool.release("MYDATABASE", client);
redis_pool.acquire("MYDATABASE", function(client){
redis_pool.acquire("MYDATABASE", function(err, client){
assert.ok(!err);
client.get("key", function(err,data){
assert.equal(data, "value");
redis_pool.release("MYDATABASE", client);