Skip to content

Commit 51ea37f

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 issue by introducing support for passing a comma separated list of hostnames to `REDIS_BACKEND` which will be expanded to an array before passing to `Credis_Cluster`. [1]: master/lib/Resque/Redis.php#L128
1 parent 78a8b4a commit 51ea37f

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ Alternately, you can always `include('bin/resque')` from your application and
301301
skip setting `APP_INCLUDE` altogether. Just be sure the various environment
302302
variables are set (`setenv`) before you do.
303303

304+
### Clustering support
305+
306+
Clustering support is automatically enabled when the `REDIS_BACKEND` environment
307+
variable contains a comma separated list of hostnames
308+
(`10.0.0.1:6379,10.0.0.2:6379`).
309+
304310
### Logging
305311

306312
The port supports the same environment variables for logging to STDOUT. Setting

bin/resque

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ $REDIS_BACKEND = getenv('REDIS_BACKEND');
4040

4141
// A redis database number
4242
$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);
43+
44+
if (!empty($REDIS_BACKEND)) {
45+
if (empty($REDIS_BACKEND_DB)) {
46+
if (stripos($REDIS_BACKEND, ',') !== false) {
47+
Resque::setBackend(explode(",", $REDIS_BACKEND));
48+
} else {
49+
Resque::setBackend($REDIS_BACKEND);
50+
}
51+
} else {
52+
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
53+
}
4854
}
4955

5056
$logLevel = false;

0 commit comments

Comments
 (0)