forked from dfoody/kue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpool.js
More file actions
43 lines (32 loc) · 623 Bytes
/
Copy pathpool.js
File metadata and controls
43 lines (32 loc) · 623 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*!
* kue - pool
* Copyright (c) 2010 LearnBoost <tj@learnboost.com>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var redis = require('../redis');
/**
* Max connections in the pool.
*/
exports.maxConnections = 5;
/**
* Connection pool.
*/
exports.pool = [];
/**
* Allocate a redis connection.
*
* @return {RedisClient}
* @api private
*/
exports.alloc = function(){
var client;
if (exports.pool.length == exports.maxConnections) {
client = exports.pool[Math.random() * exports.maxConnections | 0];
} else {
exports.pool.push(client = redis.createClient());
}
return client;
};