redis-connection-pool
Advanced tools
Comparing version 0.1.3 to 1.0.0
@@ -32,18 +32,18 @@ var indexSectionsWithContent = { | ||
}, | ||
"General": { | ||
"Functions": { | ||
"Symbols": false, | ||
"Numbers": false, | ||
"A": false, | ||
"B": false, | ||
"B": true, | ||
"C": true, | ||
"D": true, | ||
"E": true, | ||
"F": true, | ||
"G": false, | ||
"H": false, | ||
"F": false, | ||
"G": true, | ||
"H": true, | ||
"I": false, | ||
"J": true, | ||
"J": false, | ||
"K": false, | ||
"L": false, | ||
"M": true, | ||
"L": true, | ||
"M": false, | ||
"N": false, | ||
@@ -63,18 +63,18 @@ "O": true, | ||
}, | ||
"Functions": { | ||
"General": { | ||
"Symbols": false, | ||
"Numbers": false, | ||
"A": false, | ||
"B": true, | ||
"B": false, | ||
"C": true, | ||
"D": true, | ||
"E": true, | ||
"F": false, | ||
"G": true, | ||
"H": true, | ||
"F": true, | ||
"G": false, | ||
"H": false, | ||
"I": false, | ||
"J": false, | ||
"J": true, | ||
"K": false, | ||
"L": true, | ||
"M": false, | ||
"L": false, | ||
"M": true, | ||
"N": false, | ||
@@ -81,0 +81,0 @@ "O": true, |
{ | ||
"name": "redis-connection-pool", | ||
"version": "0.1.3", | ||
"version": "1.0.0", | ||
"description": "a redis client connection pool", | ||
"license": "LGPL", | ||
"license": "MIT", | ||
"private": false, | ||
@@ -24,2 +24,3 @@ "keywords": [ | ||
"dependencies": { | ||
"debug": "^2.1.0", | ||
"generic-pool": "^2.0.4", | ||
@@ -26,0 +27,0 @@ "hiredis": "^0.1.17", |
@@ -27,3 +27,8 @@ node-redis-connection-pool | ||
```javascript | ||
var redisPool = require('redis-connection-pool')('myRedisPool'); | ||
var redisPool = require('redis-connection-pool')('myRedisPool',{ | ||
host: '127.0.0.1', //default | ||
port: 6379, //default | ||
max_clients: 30, //defalut | ||
perform_checks: false //checks for needed push/pop functionality | ||
}); | ||
@@ -91,4 +96,3 @@ redisPool.set('test-key', 'foobar', function (err) { | ||
## API Documentation | ||
node-redis-connection-pool uses NaturalDocs to generate API documentation, which can be | ||
viewed after cloning the repository, in the doc/ directory, using a web browser. | ||
node-redis-connection-pool uses NaturalDocs to generate API documentation, which can be viewed after cloning the repository, in the doc/ directory, using a web browser. | ||
@@ -98,6 +102,5 @@ | ||
Licensed under the [AGPLv3](https://github.com/silverbucket/node-redis-connection-pool/blob/master/LICENSE) | ||
[MIT](https://github.com/silverbucket/node-redis-connection-pool/blob/master/LICENSE) | ||
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/silverbucket/node-redis-connectoin-pool/trend.png)](https://bitdeli.com/free "Bitdeli Badge") | ||
@@ -6,3 +6,3 @@ /** | ||
* | ||
* licensed under the LGPL. | ||
* licensed under the MIT license. | ||
* See the LICENSE file for details. | ||
@@ -19,5 +19,6 @@ * | ||
var redis = require('redis'); | ||
var Q = require('q'); | ||
var Pool = require('generic-pool').Pool; | ||
var redis = require('redis'), | ||
Q = require('q'), | ||
Pool = require('generic-pool').Pool, | ||
debug = require('debug')('redis-connection-pool'); | ||
@@ -36,3 +37,3 @@ /** | ||
* elsewhere in an application. If left undefined, one will | ||
* be generate automatically and avaialble via the `UID` | ||
* be generate automatically and avaialble via the `uid` | ||
* property of the returned object. | ||
@@ -44,10 +45,10 @@ * | ||
* | ||
* cfg.HOST - (string) - Redis host (default: "127.0.0.1") | ||
* cfg.host - (string) - Redis host (default: "127.0.0.1") | ||
* | ||
* cfg.PORT - (number) - Redis port (default: 6379) | ||
* cfg.port - (number) - Redis port (default: 6379) | ||
* | ||
* cfg.MAX_CLIENTS - (number) - Max clients alive in the connection pool at | ||
* cfg.max_clients - (number) - Max clients alive in the connection pool at | ||
* once. (default: 30) | ||
* | ||
* cfg.PERFORM_CHECKS - (boolean) - Perform a series of redis checks, | ||
* cfg.perform_checks - (boolean) - Perform a series of redis checks, | ||
* currently this checks to to see if | ||
@@ -62,8 +63,12 @@ * blocking push/pops can be used. | ||
function RedisConnectionPool(uid, cfg) { | ||
this.UID = (typeof uid ==='string') ? uid : this.UID + Math.floor((Math.random() * 99999) + 10000); | ||
this.DEBUG = (typeof cfg.DEBUG === 'boolean') ? cfg.DEBUG : this.DEBUG; | ||
this.HOST = (typeof cfg.HOST === 'string') ? cfg.HOST : this.HOST; | ||
this.PORT = (typeof cfg.PORT === 'number') ? cfg.PORT : this.PORT; | ||
this.MAX_CLIENTS = (typeof cfg.MAX_CLIENTS === 'number') ? cfg.MAX_CLIENTS : this.MAX_CLIENTS; | ||
this.PERFORM_CHECKS = (typeof cfg.PERFORM_CHECKS === 'boolean') ? cfg.PERFORM_CHECKS : this.PERFORM_CHECKS; | ||
this.uid = (typeof uid ==='string') ? uid : 'redis-connection-pool-' + Math.floor((Math.random() * 99999) + 10000); | ||
this.host = (typeof cfg.host === 'string') ? cfg.host : '127.0.0.1'; | ||
this.port = (typeof cfg.port === 'number') ? cfg.port : 6379; | ||
this.max_clients = (typeof cfg.max_clients === 'number') ? cfg.max_clients : 30; | ||
this.perform_checks = (typeof cfg.perform_checks === 'boolean') ? cfg.perform_checks : false; | ||
this.blocking_support = true; | ||
this.version_array = undefined; | ||
this.version_string = undefined; | ||
var self = this; | ||
@@ -73,10 +78,10 @@ | ||
this.pool = Pool({ | ||
name: self.UID, | ||
name: self.uid, | ||
create: function (callback) { | ||
var client = redis.createClient(self.PORT, self.HOST); | ||
client.__name = "client"+i; | ||
var client = redis.createClient(self.port, self.host); | ||
client.__name = "client" + i; | ||
i = i + 1; | ||
client.on('error', function (err) { | ||
console.log('ERROR: '+err); | ||
debug(err); | ||
}); | ||
@@ -91,4 +96,4 @@ | ||
}, | ||
max: self.MAX_CLIENTS, | ||
log: this.DEBUG | ||
max: self.max_clients, | ||
log: false | ||
}); | ||
@@ -98,11 +103,9 @@ | ||
if (self.DEBUG) { | ||
setTimeout(function poolStats() { | ||
// periodically report pool statistics | ||
console.log('REDIS POOL: [size: ' + pool.getPoolSize() + | ||
' avail:' + pool.availableObjectsCount() + | ||
' waiting:' + pool.waitingClientsCount() + ']'); | ||
setTimeout(poolStats, 300000); | ||
}, 300000); | ||
} | ||
setTimeout(function poolStats() { | ||
// periodically report pool statistics | ||
debug('REDIS POOL: [size: ' + pool.getPoolSize() + | ||
' avail:' + pool.availableObjectsCount() + | ||
' waiting:' + pool.waitingClientsCount() + ']'); | ||
setTimeout(poolStats, 300000); | ||
}, 300000); | ||
@@ -112,14 +115,4 @@ return this; | ||
RedisConnectionPool.prototype = { | ||
UID: 'redis-connection-pool-', | ||
DEBUG: false, | ||
HOST: '127.0.0.1', | ||
PORT: 6379, | ||
MAX_CLIENTS: 30, | ||
BLOCKING_SUPPORT: true, | ||
PERFORM_CHECKS: false, | ||
VERSION_ARRAY: undefined, | ||
VERSION_STRING: undefined | ||
}; | ||
/** | ||
@@ -323,3 +316,3 @@ * Function: on | ||
RedisConnectionPool.prototype.clean = function (key, cb) { | ||
console.log('redis-connection-pool: clearing redis key ' + key); | ||
debug('`clearing redis key ' + key); | ||
var client = redis.createClient(); | ||
@@ -332,10 +325,10 @@ var self = this; | ||
keys.forEach(function (name, pos) { | ||
console.log('redis-connection-pool: deleting name ' + name); | ||
debug('redis-connection-pool: deleting name ' + name); | ||
self.del(name); | ||
}); | ||
} else { | ||
console.log('ERROR redis-connection-pool: couldnt get keys list on key \'' + key + '\': ', keys); | ||
debug('ERROR couldnt get keys list on key \'' + key + '\': ', keys); | ||
} | ||
if (err) { | ||
console.log('ERROR redis-connection-pool: failed clearing redis queue. ' + err); | ||
debug('ERROR failed clearing redis queue. ' + err); | ||
} | ||
@@ -388,2 +381,3 @@ cb(); | ||
} | ||
pool.acquire(function (err, client) { | ||
@@ -394,3 +388,3 @@ if (funcName === 'hset') { | ||
if (err) { | ||
console.log("ERROR redis-connection-pool: " + funcName + ": " + err); | ||
debug("ERROR " + funcName + ": " + err); | ||
} | ||
@@ -405,3 +399,3 @@ if (typeof cb === 'function') { | ||
if (err) { | ||
console.log("ERROR redis-connection-pool: " + funcName + ": " + err); | ||
debug("ERROR " + funcName + ": " + err); | ||
} | ||
@@ -416,3 +410,3 @@ if (typeof cb === 'function') { | ||
if (err) { | ||
console.log("ERROR redis-connection-pool: " + err); | ||
debug("ERROR " + err); | ||
} | ||
@@ -460,3 +454,3 @@ if (typeof cb === 'function') { | ||
if (err) { | ||
console.log('ERROR: redis error (' + funcName + ' ' + key + ')', err); | ||
debug('ERROR: redis error (' + funcName + ' ' + key + ')', err); | ||
cb(err, null); | ||
@@ -470,3 +464,3 @@ } else { | ||
if (!responded) { | ||
console.log('ERROR: redis.' + funcName+' never returned (5s), destroying connection. ' + key); | ||
debug('ERROR: redis.' + funcName+' never returned (5s), destroying connection. ' + key); | ||
pool.destroy(client); | ||
@@ -484,3 +478,3 @@ } | ||
if (err) { | ||
console.log('ERROR: redis error (hget ' + key + ')', err); | ||
debug('ERROR: redis error (hget ' + key + ')', err); | ||
cb(err, null); | ||
@@ -495,3 +489,3 @@ } else { | ||
if (err) { | ||
console.log('ERROR: redis error (hget ' + key + ')', err); | ||
debug('ERROR: redis error (hget ' + key + ')', err); | ||
cb(err, null); | ||
@@ -513,6 +507,6 @@ } else { | ||
if (err) { | ||
console.log('ERROR redis-connection-pool: (' + funcName + ')', err); | ||
debug('ERROR (' + funcName + ')', err); | ||
cb(err, null); | ||
} else if ((!replies) || (typeof replies[1] === 'undefined')) { | ||
console.log('ERROR redis-connection-pool: got a bad reply: ', replies); | ||
debug('ERROR got a bad reply: ', replies); | ||
cb('got bad reply from redis', []); | ||
@@ -529,3 +523,3 @@ } else { | ||
var self = this; | ||
var client = redis.createClient(self.PORT, self.HOST); | ||
var client = redis.createClient(self.port, self.host); | ||
try { | ||
@@ -537,12 +531,12 @@ client.on('error', function (err) { | ||
client.on('ready', function () { | ||
self.VERSION_STRING = client.server_info.redis_version; | ||
self.VERSION_ARRAY = client.server_info.versions; | ||
if (self.VERSION_ARRAY[0] < 2) { | ||
self.BLOCKING_SUPPORT = false; | ||
self.version_string = client.server_info.redis_version; | ||
self.version_array = client.server_info.versions; | ||
if (self.version_array[0] < 2) { | ||
self.blocking_support = false; | ||
} | ||
client.quit(); | ||
q.resolve(self.VERSION_STRING); | ||
q.resolve(self.version_string); | ||
}); | ||
} catch (e) { | ||
console.log('ERROR redis-connection-pool: cannot connect to redis, ' + e); | ||
debug('ERROR cannot connect to redis, ' + e); | ||
q.reject('cannot connect to redis: ' + e); | ||
@@ -549,0 +543,0 @@ client.quit(); |
@@ -15,9 +15,9 @@ if (typeof define !== 'function') { | ||
env.redisPool = require('./../src/redis-connection-pool')('redisPoolTests', { | ||
HOST: '127.0.0.1', | ||
PORT: 6379, | ||
MAX_CLIENTS: 60, | ||
PERFORM_CHECKS: true | ||
host: '127.0.0.1', | ||
port: 6379, | ||
max_clients: 60, | ||
perform_checks: true | ||
}); | ||
test.assertTypeAnd(env.redisPool, 'object'); | ||
test.assertAnd(env.redisPool.UID, 'redisPoolTests'); | ||
test.assertAnd(env.redisPool.uid, 'redisPoolTests'); | ||
env.redisPool.clean(env.channel + '*', function () { | ||
@@ -49,4 +49,4 @@ test.result(true); | ||
run: function (env, test) { | ||
test.assertTypeAnd(env.redisPool.VERSION_STRING, 'string'); | ||
test.assertType(env.redisPool.VERSION_ARRAY, 'object'); | ||
test.assertTypeAnd(env.redisPool.version_string, 'string'); | ||
test.assertType(env.redisPool.version_array, 'object'); | ||
} | ||
@@ -53,0 +53,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
0
104
278848
5
3509
+ Addeddebug@^2.1.0
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)