Skip to content

Commit e8bf589

Browse files
committed
bin/resque: add support for connecting with a cluster client
As `bin/resque` currently works, it pulls in the hostname to use from the environment using `getenv`. The problem with this is that you cannot pass in an array which is what the underlying Redis library uses[1] to determine whether it initialises a `Credis_Client` or a `Credit_Cluster` for the connection. This solves that by introducing a new environment variable (`REDIS_CLUSTER_ENABLED`) to determine when it should expand a comma separated list of hosts to define as a cluster. [1]: master/lib/Resque/Redis.php#L128
1 parent 78a8b4a commit e8bf589

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

bin/resque

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,23 @@ if(empty($QUEUE)) {
3737
* Note: the 'user' part of the DSN URI is required but is not used.
3838
*/
3939
$REDIS_BACKEND = getenv('REDIS_BACKEND');
40+
$REDIS_CLUSTER_ENABLED = getenv('REDIS_CLUSTER_ENABLED');
4041

4142
// A redis database number
4243
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
43-
if(!empty($REDIS_BACKEND)) {
44-
if (empty($REDIS_BACKEND_DB))
45-
Resque::setBackend($REDIS_BACKEND);
46-
else
47-
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
44+
if (!empty($REDIS_BACKEND)) {
45+
if (empty($REDIS_BACKEND_DB)) {
46+
// Should we have clustering enabled, we accept a comma separated list of
47+
// servers to pass to the backend. This tells the underlying client we should
48+
// use the specific cluster client.
49+
if (filter_var($REDIS_CLUSTER_ENABLED, FILTER_VALIDATE_BOOLEAN)) {
50+
Resque::setBackend(explode(",", $REDIS_BACKEND));
51+
} else {
52+
Resque::setBackend($REDIS_BACKEND);
53+
}
54+
} else {
55+
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
56+
}
4857
}
4958

5059
$logLevel = false;

0 commit comments

Comments
 (0)