Permalink
Browse files

Removed unnecessary "pooling"

that wasnt even really pooling anyway,
cant remember why we had this
  • Loading branch information...
tj committed Sep 29, 2011
1 parent dc4db8f commit b7f8d3b065083f53bc75cf297b0d5b479f9d9195
Showing with 32 additions and 37 deletions.
  1. +3 −3 lib/queue/events.js
  2. +7 −8 lib/queue/job.js
  3. +0 −10 lib/queue/pool.js
  4. +22 −1 lib/redis.js
  5. +0 −15 test.js
View
@@ -9,7 +9,7 @@
* Module dependencies.
*/
-var pool = require('./pool');
+var redis = require('../redis');
/**
* Job map.
@@ -44,7 +44,7 @@ exports.add = function(job){
*/
exports.subscribe = function(){
- var client = pool.pubsubClient();
+ var client = redis.pubsubClient();
client.subscribe(exports.key);
client.on('message', exports.onMessage);
exports.queue = require('../kue').singleton;
@@ -85,7 +85,7 @@ exports.onMessage = function(channel, msg){
*/
exports.emit = function(id, event) {
- var client = pool.alloc()
+ var client = redis.client()
, msg = JSON.stringify({
id: id
, event: event
View
@@ -11,7 +11,7 @@
var EventEmitter = require('events').EventEmitter
, events = require('./events')
- , pool = require('./pool')
+ , redis = require('../redis')
, reds = require('reds')
, noop = function(){};
@@ -101,7 +101,7 @@ function get(fn, order) {
*/
exports.range = function(from, to, order, fn){
- pool.alloc().zrange('q:jobs', from, to, get(fn, order));
+ redis.client().zrange('q:jobs', from, to, get(fn, order));
};
/**
@@ -117,7 +117,7 @@ exports.range = function(from, to, order, fn){
*/
exports.rangeByState = function(state, from, to, order, fn){
- pool.alloc().zrange('q:jobs:' + state, from, to, get(fn, order));
+ redis.client().zrange('q:jobs:' + state, from, to, get(fn, order));
};
/**
@@ -134,7 +134,7 @@ exports.rangeByState = function(state, from, to, order, fn){
*/
exports.rangeByType = function(type, state, from, to, order, fn){
- pool.alloc().zrange('q:jobs:' + type + ':' + state, from, to, get(fn, order));
+ redis.client().zrange('q:jobs:' + type + ':' + state, from, to, get(fn, order));
};
/**
@@ -146,7 +146,7 @@ exports.rangeByType = function(type, state, from, to, order, fn){
*/
exports.get = function(id, fn){
- var client = pool.alloc()
+ var client = redis.client()
, job = new Job;
job.id = id;
@@ -202,8 +202,7 @@ exports.remove = function(id, fn){
*/
exports.log = function(id, fn){
- var client = pool.alloc();
- client.lrange('q:job:' + id + ':log', 0, -1, fn);
+ redis.client().lrange('q:job:' + id + ':log', 0, -1, fn);
};
/**
@@ -217,7 +216,7 @@ exports.log = function(id, fn){
function Job(type, data) {
this.type = type;
this.data = data || {};
- this.client = pool.alloc();
+ this.client = redis.client();
this.priority('normal');
}
View
@@ -40,14 +40,4 @@ exports.alloc = function(){
return client;
};
-/**
- * Return the pubsub-specific redis client.
- *
- * @return {RedisClient}
- * @api private
- */
-
-exports.pubsubClient = function(){
- return exports._pubsub || (exports._pubsub = redis.createClient());
-};
View
@@ -13,7 +13,7 @@
var redis = require('redis');
/**
- * Create a RedisClient
+ * Create a RedisClient.
*
* @return {RedisClient}
* @api private
@@ -23,3 +23,24 @@ exports.createClient = function(){
return redis.createClient();
};
+/**
+ * Create or return the existing RedisClient.
+ *
+ * @return {RedisClient}
+ * @api private
+ */
+
+exports.client = function(){
+ return exports._client || (exports._client = redis.createClient());
+};
+
+/**
+ * Return the pubsub-specific redis client.
+ *
+ * @return {RedisClient}
+ * @api private
+ */
+
+exports.pubsubClient = function(){
+ return exports._pubsub || (exports._pubsub = exports.createClient());
+};
View
15 test.js
@@ -1,15 +0,0 @@
-
-var kue = require('./')
- , Job = kue.Job;
-
-// create our job queue
-
-var jobs = kue.createQueue();
-
-jobs.on('job complete', function(id){
- console.log('got %d', id);
- Job.get(id, function(err, job){
- if (err) return;
- console.log(job.data);
- });
-});

0 comments on commit b7f8d3b

Please sign in to comment.