Allows a callable to be passed to Resque::setBackend for setting Resque::

This commit is contained in:
vincent zhao 2014-09-25 10:31:09 +10:00
parent f14e844c45
commit bc9dac71ca

View File

@ -33,6 +33,8 @@ class Resque
* the redis server that Resque will talk to. * the redis server that Resque will talk to.
* *
* @param mixed $server Host/port combination separated by a colon, DSN-formatted URI, or * @param mixed $server Host/port combination separated by a colon, DSN-formatted URI, or
* a callable that receives the configured database ID
* and returns a Resque_Redis instance, or
* a nested array of servers with host/port pairs. * a nested array of servers with host/port pairs.
* @param int $database * @param int $database
*/ */
@ -54,7 +56,12 @@ class Resque
return self::$redis; return self::$redis;
} }
if (is_callable(self::$redisServer)) {
self::$redis = call_user_func(self::$redisServer, self::$redisDatabase);
} else {
self::$redis = new Resque_Redis(self::$redisServer, self::$redisDatabase); self::$redis = new Resque_Redis(self::$redisServer, self::$redisDatabase);
}
return self::$redis; return self::$redis;
} }