@@ -33,6 +33,8 @@ class Resque
3333 * the redis server that Resque will talk to.
3434 *
3535 * @param mixed $server Host/port combination separated by a colon, DSN-formatted URI, or
36+ * a callable that receives the configured database ID
37+ * and returns a Resque_Redis instance, or
3638 * a nested array of servers with host/port pairs.
3739 * @param int $database
3840 */
@@ -54,10 +56,15 @@ public static function redis()
5456 return self ::$ redis ;
5557 }
5658
57- self ::$ redis = new Resque_Redis (self ::$ redisServer , self ::$ redisDatabase );
59+ if (is_callable (self ::$ redisServer )) {
60+ self ::$ redis = call_user_func (self ::$ redisServer , self ::$ redisDatabase );
61+ } else {
62+ self ::$ redis = new Resque_Redis (self ::$ redisServer , self ::$ redisDatabase );
63+ }
64+
5865 return self ::$ redis ;
5966 }
60-
67+
6168 /**
6269 * fork() helper method for php-resque that handles issues PHP socket
6370 * and phpredis have with passing around sockets between child/parent
@@ -135,7 +142,7 @@ public static function dequeue($queue, $items = Array())
135142 return self ::removeList ($ queue );
136143 }
137144 }
138-
145+
139146 /**
140147 * Pop an item off the end of the specified queues, using blocking list pop,
141148 * decode it and return it.
@@ -324,7 +331,7 @@ private static function matchItem($string, $items)
324331 * Remove List
325332 *
326333 * @private
327- *
334+ *
328335 * @params string $queue the name of the queue
329336 * @return integer number of deleted items belongs to this list
330337 */
0 commit comments