Skip to content

Commit 4cbf3c0

Browse files
committed
Merge pull request #89 from trimbletodd/master
Adding support for remote redis instances (such as redistogo) that require authentication
2 parents fff22a6 + 6a429c2 commit 4cbf3c0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/Resque/Redis.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function __construct($server, $database = null)
101101
}
102102
else {
103103
$port = null;
104+
$password = null;
104105
$host = $server;
105106

106107
// If not a UNIX socket path or tcp:// formatted connections string
@@ -111,8 +112,19 @@ public function __construct($server, $database = null)
111112
$port = $parts[1];
112113
}
113114
$host = $parts[0];
115+
}else if (strpos($server, 'redis://') !== false){
116+
// Redis format is:
117+
// redis://[user]:[password]@[host]:[port]
118+
list($userpwd,$hostport) = explode('@', $server);
119+
$userpwd = substr($userpwd, strpos($userpwd, 'redis://')+8);
120+
list($host, $port) = explode(':', $hostport);
121+
list($user, $password) = explode(':', $userpwd);
114122
}
123+
115124
$this->driver = new Credis_Client($host, $port);
125+
if (isset($password)){
126+
$this->driver->auth($password);
127+
}
116128
}
117129

118130
if ($this->database !== null) {

0 commit comments

Comments
 (0)