Skip to content

Commit fe41c04

Browse files
authored
Merge pull request #35 from JohnPremKumar/patch-1
Support Redis Password Encoding
2 parents b6a920c + 996df49 commit fe41c04

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/Resque/Redis.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ public static function parseDsn($dsn)
207207
$database = intval(preg_replace('/[^0-9]/', '', $parts['path']));
208208
}
209209

210-
// Extract any 'user' and 'pass' values
210+
// Extract any 'user' values
211211
$user = isset($parts['user']) ? $parts['user'] : false;
212-
$pass = isset($parts['pass']) ? $parts['pass'] : false;
213212

214213
// Convert the query string into an associative array
215214
$options = array();
@@ -218,6 +217,20 @@ public static function parseDsn($dsn)
218217
parse_str($parts['query'], $options);
219218
}
220219

220+
//check 'password-encoding' parameter and extracting password based on encoding
221+
if($options && isset($options['password-encoding']) && $options['password-encoding'] === 'u'){
222+
//extracting urlencoded password
223+
$pass = isset($parts['pass']) ? urldecode($parts['pass']) : false;
224+
}
225+
else if($options && isset($options['password-encoding']) && $options['password-encoding'] === 'b'){
226+
//extracting base64 encoded password
227+
$pass = isset($parts['pass']) ? base64_decode($parts['pass']) : false;
228+
}
229+
else{
230+
//extracting pass directly since 'password-encoding' parameter is not present
231+
$pass = isset($parts['pass']) ? $parts['pass'] : false;
232+
}
233+
221234
return array(
222235
$parts['host'],
223236
$port,

0 commit comments

Comments
 (0)