From ad33efbc675f19450d4f3c5edc5a37ac7e1ac724 Mon Sep 17 00:00:00 2001 From: Iskandar Najmuddin Date: Mon, 5 May 2014 13:02:16 +0000 Subject: [PATCH 1/9] Improve Resque_Redis DSN parsing. - Allow for DSN URIs to work as expected. - Backward-compatible with simple 'host:port' format. - Does not parse DSNs provided in array format for Credis_Cluster. --- lib/Resque/Redis.php | 121 +++++++++++++++++++------- test/Resque/Tests/DsnTest.php | 157 ++++++++++++++++++++++++++++++++++ 2 files changed, 246 insertions(+), 32 deletions(-) mode change 100644 => 100755 lib/Resque/Redis.php create mode 100755 test/Resque/Tests/DsnTest.php diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php old mode 100644 new mode 100755 index 6cef3d2..e44a962 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -8,14 +8,29 @@ */ class Resque_Redis { - /** - * Redis namespace - * @var string - */ - private static $defaultNamespace = 'resque:'; + /** + * Redis namespace + * @var string + */ + private static $defaultNamespace = 'resque:'; - private $server; - private $database; + /** + * A default host to connect to + */ + const DEFAULT_HOST = 'localhost'; + + /** + * The default Redis port + */ + const DEFAULT_PORT = 6379; + + /** + * The default Redis Database number + */ + const DEFAULT_DATABASE = 0; + + private $server; + private $database; /** * @var array List of all commands in Redis that supply a key as their @@ -92,40 +107,36 @@ class Resque_Redis self::$defaultNamespace = $namespace; } - public function __construct($server, $database = null) + /** + * @param string|array $server A DSN or array + * @param int $database A database number to select + */ + public function __construct($server, $database = null) { $this->server = $server; $this->database = $database; if (is_array($this->server)) { $this->driver = new Credis_Cluster($server); - } - else { - $port = null; - $password = null; - $host = $server; - // If not a UNIX socket path or tcp:// formatted connections string - // assume host:port combination. - if (strpos($server, '/') === false) { - $parts = explode(':', $server); - if (isset($parts[1])) { - $port = $parts[1]; - } - $host = $parts[0]; - }else if (strpos($server, 'redis://') !== false){ - // Redis format is: - // redis://[user]:[password]@[host]:[port] - list($userpwd,$hostport) = explode('@', $server); - $userpwd = substr($userpwd, strpos($userpwd, 'redis://')+8); - list($host, $port) = explode(':', $hostport); - list($user, $password) = explode(':', $userpwd); - } - - $this->driver = new Credis_Client($host, $port); - if (isset($password)){ + } else { + + list($host, $port, $dsnDatabase, $user, $password, $options) = $this->parseDsn($server); + // $user is are unused here + + // Look for known Credis_Client options + $timeout = isset($options['timeout']) ? intval($options['timeout']) : null; + $persistent = isset($options['persistent']) ? $options['persistent'] : ''; + + $this->driver = new Credis_Client($host, $port, $timeout, $persistent); + if ($password){ $this->driver->auth($password); } + + // If the `$database` constructor argument is not set, use the value from the DSN. + if (is_null($database)) { + $database = $dsnDatabase; + } } if ($this->database !== null) { @@ -133,6 +144,52 @@ class Resque_Redis } } + /** + * Parse a DSN string + * @param string $dsn + * @return array [host, port, db, user, pass, options] + */ + public function parseDsn($dsn) + { + $validSchemes = array('redis', 'tcp'); + if ($dsn == '') { + // Use a sensible default for an empty DNS string + $dsn = 'redis://' . self::DEFAULT_HOST; + } + $parts = parse_url($dsn); + if (isset($parts['scheme']) && ! in_array($parts['scheme'], $validSchemes)) { + throw new \InvalidArgumentException("Invalid DSN. Supported schemes are " . implode(', ', $validSchemes)); + } + + // Allow simple 'hostname' format, which parse_url treats as a path, not host. + if ( ! isset($parts['host'])) { + $parts = array('host' => $parts['path']); + } + + $port = isset($parts['port']) ? intval($parts['port']) : self::DEFAULT_PORT; + + $database = self::DEFAULT_DATABASE; + if (isset($parts['path'])) { + // Strip non-digit chars from path + $database = intval(preg_replace('/[^0-9]/', '', $parts['path'])); + } + + $options = array(); + if (isset($parts['query'])) { + // Parse the query string into an array + parse_str($parts['query'], $options); + } + + return array( + $parts['host'], + $port, + $database, + isset($parts['user']) ? $parts['user'] : false, + isset($parts['pass']) ? $parts['pass'] : false, + $options, + ); + } + /** * Magic method to handle all function requests and prefix key based * operations with the {self::$defaultNamespace} key prefix. diff --git a/test/Resque/Tests/DsnTest.php b/test/Resque/Tests/DsnTest.php new file mode 100755 index 0000000..c9cd471 --- /dev/null +++ b/test/Resque/Tests/DsnTest.php @@ -0,0 +1,157 @@ + + * @license http://www.opensource.org/licenses/mit-license.php + */ +class Resque_Tests_DsnTest extends Resque_Tests_TestCase +{ + + /** + * These DNS strings are considered valid. + * + * @return array + */ + public function validDsnStringProvider() + { + return array( + // Input , Expected output + array('', array( + 'localhost', + Resque_Redis::DEFAULT_PORT, + Resque_Redis::DEFAULT_DATABASE, + false, false, + array(), + )), + array('localhost', array( + 'localhost', + Resque_Redis::DEFAULT_PORT, + Resque_Redis::DEFAULT_DATABASE, + false, false, + array(), + )), + array('localhost:1234', array( + 'localhost', + 1234, + Resque_Redis::DEFAULT_DATABASE, + false, false, + array(), + )), + array('localhost:1234/2', array( + 'localhost', + 1234, + 2, + false, false, + array(), + )), + array('redis://foobar', array( + 'foobar', + Resque_Redis::DEFAULT_PORT, + Resque_Redis::DEFAULT_DATABASE, + false, false, + array(), + )), + array('redis://foobar:1234', array( + 'foobar', + 1234, + Resque_Redis::DEFAULT_DATABASE, + false, false, + array(), + )), + array('redis://user@foobar:1234', array( + 'foobar', + 1234, + Resque_Redis::DEFAULT_DATABASE, + 'user', false, + array(), + )), + array('redis://user:pass@foobar:1234', array( + 'foobar', + 1234, + Resque_Redis::DEFAULT_DATABASE, + 'user', 'pass', + array(), + )), + array('redis://user:pass@foobar:1234?x=y&a=b', array( + 'foobar', + 1234, + Resque_Redis::DEFAULT_DATABASE, + 'user', 'pass', + array('x' => 'y', 'a' => 'b'), + )), + array('redis://:pass@foobar:1234?x=y&a=b', array( + 'foobar', + 1234, + Resque_Redis::DEFAULT_DATABASE, + false, 'pass', + array('x' => 'y', 'a' => 'b'), + )), + array('redis://user@foobar:1234?x=y&a=b', array( + 'foobar', + 1234, + Resque_Redis::DEFAULT_DATABASE, + 'user', false, + array('x' => 'y', 'a' => 'b'), + )), + array('redis://foobar:1234?x=y&a=b', array( + 'foobar', + 1234, + Resque_Redis::DEFAULT_DATABASE, + false, false, + array('x' => 'y', 'a' => 'b'), + )), + array('redis://user@foobar:1234/12?x=y&a=b', array( + 'foobar', + 1234, + 12, + 'user', false, + array('x' => 'y', 'a' => 'b'), + )), + array('tcp://user@foobar:1234/12?x=y&a=b', array( + 'foobar', + 1234, + 12, + 'user', false, + array('x' => 'y', 'a' => 'b'), + )), + ); + } + + /** + * These DSN values should throw exceptions + * @return array + */ + public function bogusDsnStringProvider() + { + return array( + 'http://foo.bar/', + '://foo.bar/', + 'user:@foobar:1234?x=y&a=b', + 'foobar:1234?x=y&a=b', + ); + } + + /** + * @dataProvider validDsnStringProvider + */ + public function testParsingValidDsnString($dsn, $expected) + { + $resqueRedis = new Resque_Redis('localhost'); + $result = $resqueRedis->parseDsn($dsn); + $this->assertEquals($expected, $result); + } + + /** + * @dataProvider bogusDsnStringProvider + * @expectedException InvalidArgumentException + */ + public function testParsingBogusDsnStringThrowsException($dsn) + { + $resqueRedis = new Resque_Redis('localhost'); + // The next line should throw an InvalidArgumentException + $result = $resqueRedis->parseDsn($dsn); + } + +} From 1abbad3f5ee83ef05b19199bdbb29f7176c5eb7d Mon Sep 17 00:00:00 2001 From: Iskandar Najmuddin Date: Mon, 5 May 2014 14:47:43 +0000 Subject: [PATCH 2/9] Improve comments and readability --- demo/check_status.php | 3 +++ demo/queue.php | 4 ++++ lib/Resque.php | 2 +- lib/Resque/Redis.php | 43 +++++++++++++++++++++++++---------- test/Resque/Tests/DsnTest.php | 14 ++++++++++++ 5 files changed, 53 insertions(+), 13 deletions(-) mode change 100644 => 100755 demo/check_status.php mode change 100644 => 100755 demo/queue.php mode change 100644 => 100755 lib/Resque.php diff --git a/demo/check_status.php b/demo/check_status.php old mode 100644 new mode 100755 index 645bf6d..871daba --- a/demo/check_status.php +++ b/demo/check_status.php @@ -7,6 +7,9 @@ require __DIR__ . '/init.php'; date_default_timezone_set('GMT'); Resque::setBackend('127.0.0.1:6379'); +// You can also use a DSN-style format: +//Resque::setBackend('redis://user:pass@127.0.0.1:6379'); +//Resque::setBackend('redis://user:pass@a.host.name:3432/2'); $status = new Resque_Job_Status($argv[1]); if(!$status->isTracking()) { diff --git a/demo/queue.php b/demo/queue.php old mode 100644 new mode 100755 index 52f2f0b..1eca124 --- a/demo/queue.php +++ b/demo/queue.php @@ -7,6 +7,10 @@ require __DIR__ . '/init.php'; date_default_timezone_set('GMT'); Resque::setBackend('127.0.0.1:6379'); +// You can also use a DSN-style format: +//Resque::setBackend('redis://user:pass@127.0.0.1:6379'); +//Resque::setBackend('redis://user:pass@a.host.name:3432/2'); + $args = array( 'time' => time(), 'array' => array( diff --git a/lib/Resque.php b/lib/Resque.php old mode 100644 new mode 100755 index 2b47084..13c841e --- a/lib/Resque.php +++ b/lib/Resque.php @@ -32,7 +32,7 @@ class Resque * Given a host/port combination separated by a colon, set it as * the redis server that Resque will talk to. * - * @param mixed $server Host/port combination separated by a colon, or + * @param mixed $server Host/port combination separated by a colon, DSN-formatted URI, or * a nested array of servers with host/port pairs. * @param int $database */ diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index e44a962..41fec07 100755 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -122,7 +122,7 @@ class Resque_Redis } else { list($host, $port, $dsnDatabase, $user, $password, $options) = $this->parseDsn($server); - // $user is are unused here + // $user is not used, only $password // Look for known Credis_Client options $timeout = isset($options['timeout']) ? intval($options['timeout']) : null; @@ -133,9 +133,11 @@ class Resque_Redis $this->driver->auth($password); } - // If the `$database` constructor argument is not set, use the value from the DSN. - if (is_null($database)) { + // If we have found a database in our DSN, use it instead of the `$database` + // value passed into the constructor + if ($dsnDatabase !== false) { $database = $dsnDatabase; + $this->database = $database; } } @@ -145,35 +147,52 @@ class Resque_Redis } /** - * Parse a DSN string - * @param string $dsn + * Parse a DSN string, which can have one of the following formats: + * + * - host:port + * - redis://user:pass@host:port/db?option1=val1&option2=val2 + * - tcp://user:pass@host:port/db?option1=val1&option2=val2 + * + * Note: the 'user' part of the DSN is not used. + * + * @param string $dsn A DSN string * @return array [host, port, db, user, pass, options] */ public function parseDsn($dsn) { - $validSchemes = array('redis', 'tcp'); if ($dsn == '') { // Use a sensible default for an empty DNS string $dsn = 'redis://' . self::DEFAULT_HOST; } $parts = parse_url($dsn); + + // Check the URI scheme + $validSchemes = array('redis', 'tcp'); if (isset($parts['scheme']) && ! in_array($parts['scheme'], $validSchemes)) { throw new \InvalidArgumentException("Invalid DSN. Supported schemes are " . implode(', ', $validSchemes)); } - // Allow simple 'hostname' format, which parse_url treats as a path, not host. - if ( ! isset($parts['host'])) { - $parts = array('host' => $parts['path']); + // Allow simple 'hostname' format, which `parse_url` treats as a path, not host. + if ( ! isset($parts['host']) && isset($parts['path'])) { + $parts['host'] = $parts['path']; + unset($parts['path']); } + // Extract the port number as an integer $port = isset($parts['port']) ? intval($parts['port']) : self::DEFAULT_PORT; - $database = self::DEFAULT_DATABASE; + // Get the database from the 'path' part of the URI + $database = false; if (isset($parts['path'])) { // Strip non-digit chars from path $database = intval(preg_replace('/[^0-9]/', '', $parts['path'])); } + // Extract any 'user' and 'pass' values + $user = isset($parts['user']) ? $parts['user'] : false; + $pass = isset($parts['pass']) ? $parts['pass'] : false; + + // Convert the query string into an associative array $options = array(); if (isset($parts['query'])) { // Parse the query string into an array @@ -184,8 +203,8 @@ class Resque_Redis $parts['host'], $port, $database, - isset($parts['user']) ? $parts['user'] : false, - isset($parts['pass']) ? $parts['pass'] : false, + $user, + $pass, $options, ); } diff --git a/test/Resque/Tests/DsnTest.php b/test/Resque/Tests/DsnTest.php index c9cd471..2fc6654 100755 --- a/test/Resque/Tests/DsnTest.php +++ b/test/Resque/Tests/DsnTest.php @@ -60,6 +60,13 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase false, false, array(), )), + array('redis://foobar:1234/15', array( + 'foobar', + 1234, + 15, + false, false, + array(), + )), array('redis://user@foobar:1234', array( 'foobar', 1234, @@ -67,6 +74,13 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase 'user', false, array(), )), + array('redis://user@foobar:1234/15', array( + 'foobar', + 1234, + 15, + 'user', false, + array(), + )), array('redis://user:pass@foobar:1234', array( 'foobar', 1234, From d1d2b3b3545dfae139cec69aa1d93de4676f6beb Mon Sep 17 00:00:00 2001 From: Iskandar Najmuddin Date: Mon, 5 May 2014 14:55:01 +0000 Subject: [PATCH 3/9] Test for 'false' database value when not found in DSN --- lib/Resque/Redis.php | 5 +++-- test/Resque/Tests/DsnTest.php | 29 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index 41fec07..be5492a 100755 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -109,7 +109,8 @@ class Resque_Redis /** * @param string|array $server A DSN or array - * @param int $database A database number to select + * @param int $database A database number to select. However, if we find a valid database number in the DSN the + * DSN-supplied value will be used instead and this parameter is ignored. */ public function __construct($server, $database = null) { @@ -134,7 +135,7 @@ class Resque_Redis } // If we have found a database in our DSN, use it instead of the `$database` - // value passed into the constructor + // value passed into the constructor. if ($dsnDatabase !== false) { $database = $dsnDatabase; $this->database = $database; diff --git a/test/Resque/Tests/DsnTest.php b/test/Resque/Tests/DsnTest.php index 2fc6654..7e483a3 100755 --- a/test/Resque/Tests/DsnTest.php +++ b/test/Resque/Tests/DsnTest.php @@ -21,21 +21,21 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase array('', array( 'localhost', Resque_Redis::DEFAULT_PORT, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), array('localhost', array( 'localhost', Resque_Redis::DEFAULT_PORT, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), array('localhost:1234', array( 'localhost', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), @@ -49,14 +49,14 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase array('redis://foobar', array( 'foobar', Resque_Redis::DEFAULT_PORT, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), array('redis://foobar:1234', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), @@ -67,10 +67,17 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase false, false, array(), )), + array('redis://foobar:1234/0', array( + 'foobar', + 1234, + 0, + false, false, + array(), + )), array('redis://user@foobar:1234', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', false, array(), )), @@ -84,35 +91,35 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase array('redis://user:pass@foobar:1234', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', 'pass', array(), )), array('redis://user:pass@foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', 'pass', array('x' => 'y', 'a' => 'b'), )), array('redis://:pass@foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, 'pass', array('x' => 'y', 'a' => 'b'), )), array('redis://user@foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', false, array('x' => 'y', 'a' => 'b'), )), array('redis://foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array('x' => 'y', 'a' => 'b'), )), From 62ed6200831e525d67c961df3523e3088c51bffd Mon Sep 17 00:00:00 2001 From: Iskandar Najmuddin Date: Mon, 5 May 2014 14:59:37 +0000 Subject: [PATCH 4/9] Put 'else' keyword on new line in keeping with project conventions --- lib/Resque/Redis.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index be5492a..bddd013 100755 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -120,7 +120,8 @@ class Resque_Redis if (is_array($this->server)) { $this->driver = new Credis_Cluster($server); - } else { + } + else { list($host, $port, $dsnDatabase, $user, $password, $options) = $this->parseDsn($server); // $user is not used, only $password From 506b769b905ede790f77e74b15e877cc3c03b289 Mon Sep 17 00:00:00 2001 From: Iskandar Najmuddin Date: Mon, 5 May 2014 15:08:00 +0000 Subject: [PATCH 5/9] Make parseDsn() method static, remove unused member vars --- lib/Resque.php | 7 +--- lib/Resque/Redis.php | 66 ++++++++++++++++------------------- test/Resque/Tests/DsnTest.php | 6 ++-- 3 files changed, 33 insertions(+), 46 deletions(-) diff --git a/lib/Resque.php b/lib/Resque.php index 13c841e..0f4b94e 100755 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -54,12 +54,7 @@ class Resque return self::$redis; } - $server = self::$redisServer; - if (empty($server)) { - $server = 'localhost:6379'; - } - - self::$redis = new Resque_Redis($server, self::$redisDatabase); + self::$redis = new Resque_Redis(self::$redisServer, self::$redisDatabase); return self::$redis; } diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index bddd013..a946b14 100755 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -29,9 +29,6 @@ class Resque_Redis */ const DEFAULT_DATABASE = 0; - private $server; - private $database; - /** * @var array List of all commands in Redis that supply a key as their * first argument. Used to prefix keys with the Resque namespace. @@ -114,16 +111,12 @@ class Resque_Redis */ public function __construct($server, $database = null) { - $this->server = $server; - $this->database = $database; - - if (is_array($this->server)) { + if (is_array($server)) { $this->driver = new Credis_Cluster($server); - } else { - list($host, $port, $dsnDatabase, $user, $password, $options) = $this->parseDsn($server); + list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server); // $user is not used, only $password // Look for known Credis_Client options @@ -139,11 +132,10 @@ class Resque_Redis // value passed into the constructor. if ($dsnDatabase !== false) { $database = $dsnDatabase; - $this->database = $database; } } - if ($this->database !== null) { + if ($database !== null) { $this->driver->select($database); } } @@ -158,9 +150,10 @@ class Resque_Redis * Note: the 'user' part of the DSN is not used. * * @param string $dsn A DSN string - * @return array [host, port, db, user, pass, options] + * @return array An array of DSN compotnents, with 'false' values for any unknown components. e.g. + * [host, port, db, user, pass, options] */ - public function parseDsn($dsn) + public static function parseDsn($dsn) { if ($dsn == '') { // Use a sensible default for an empty DNS string @@ -219,37 +212,38 @@ class Resque_Redis * @param array $args Array of supplied arguments to the method. * @return mixed Return value from Resident::call() based on the command. */ - public function __call($name, $args) { - if(in_array($name, $this->keyCommands)) { - if(is_array($args[0])) { - foreach($args[0] AS $i => $v) { - $args[0][$i] = self::$defaultNamespace . $v; - } - } else { - $args[0] = self::$defaultNamespace . $args[0]; - } + public function __call($name, $args) + { + if (in_array($name, $this->keyCommands)) { + if (is_array($args[0])) { + foreach ($args[0] AS $i => $v) { + $args[0][$i] = self::$defaultNamespace . $v; + } + } + else { + $args[0] = self::$defaultNamespace . $args[0]; + } } try { return $this->driver->__call($name, $args); } - catch(CredisException $e) { + catch (CredisException $e) { return false; } } - public static function getPrefix() - { - return self::$defaultNamespace; - } + public static function getPrefix() + { + return self::$defaultNamespace; + } - public static function removePrefix($string) - { - $prefix=self::getPrefix(); + public static function removePrefix($string) + { + $prefix=self::getPrefix(); - if (substr($string, 0, strlen($prefix)) == $prefix) { - $string = substr($string, strlen($prefix), strlen($string) ); - } - return $string; - } + if (substr($string, 0, strlen($prefix)) == $prefix) { + $string = substr($string, strlen($prefix), strlen($string) ); + } + return $string; + } } -?> \ No newline at end of file diff --git a/test/Resque/Tests/DsnTest.php b/test/Resque/Tests/DsnTest.php index 7e483a3..282a088 100755 --- a/test/Resque/Tests/DsnTest.php +++ b/test/Resque/Tests/DsnTest.php @@ -159,8 +159,7 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase */ public function testParsingValidDsnString($dsn, $expected) { - $resqueRedis = new Resque_Redis('localhost'); - $result = $resqueRedis->parseDsn($dsn); + $result = Resque_Redis::parseDsn($dsn); $this->assertEquals($expected, $result); } @@ -170,9 +169,8 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase */ public function testParsingBogusDsnStringThrowsException($dsn) { - $resqueRedis = new Resque_Redis('localhost'); // The next line should throw an InvalidArgumentException - $result = $resqueRedis->parseDsn($dsn); + $result = Resque_Redis::parseDsn($dsn); } } From b0385d29594fc91da4bc78c0209b8a8c69ae5763 Mon Sep 17 00:00:00 2001 From: Iskandar Najmuddin Date: Mon, 5 May 2014 15:11:20 +0000 Subject: [PATCH 6/9] Add comment describing REDIS_BACKEND format to bin/resque --- bin/resque | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/resque b/bin/resque index b8089ac..4cb50da 100755 --- a/bin/resque +++ b/bin/resque @@ -30,7 +30,15 @@ if(empty($QUEUE)) { die("Set QUEUE env var containing the list of queues to work.\n"); } +/** + * REDIS_BACKEND can have simple 'host:port' format or use a DSN-style format like this: + * - redis://user:pass@host:port + * + * Note: the 'user' part of the DSN URI is required but is not used. + */ $REDIS_BACKEND = getenv('REDIS_BACKEND'); + +// A redis database number $REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB'); if(!empty($REDIS_BACKEND)) { if (empty($REDIS_BACKEND_DB)) From 76412df8fd519af2b7bcc51ae209e3dc5cb80b39 Mon Sep 17 00:00:00 2001 From: Iskandar Najmuddin Date: Mon, 5 May 2014 15:29:52 +0000 Subject: [PATCH 7/9] Fix return array format of `bogusDsnStringProvider` --- test/Resque/Tests/DsnTest.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/Resque/Tests/DsnTest.php b/test/Resque/Tests/DsnTest.php index 282a088..086db1e 100755 --- a/test/Resque/Tests/DsnTest.php +++ b/test/Resque/Tests/DsnTest.php @@ -53,6 +53,13 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase false, false, array(), )), + array('redis://foobar/', array( + 'foobar', + Resque_Redis::DEFAULT_PORT, + false, + false, false, + array(), + )), array('redis://foobar:1234', array( 'foobar', 1234, @@ -147,10 +154,9 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase public function bogusDsnStringProvider() { return array( - 'http://foo.bar/', - '://foo.bar/', - 'user:@foobar:1234?x=y&a=b', - 'foobar:1234?x=y&a=b', + array('http://foo.bar/'), + array('user:@foobar:1234?x=y&a=b'), + array('foobar:1234?x=y&a=b'), ); } From 3b074a046a16f8b3b463ae6de056e4fb2945c6eb Mon Sep 17 00:00:00 2001 From: Iskandar Najmuddin Date: Mon, 5 May 2014 17:47:39 +0000 Subject: [PATCH 8/9] Revert file modes back to 644 --- demo/check_status.php | 0 demo/queue.php | 0 lib/Resque.php | 0 lib/Resque/Redis.php | 0 test/Resque/Tests/DsnTest.php | 0 5 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 demo/check_status.php mode change 100755 => 100644 demo/queue.php mode change 100755 => 100644 lib/Resque.php mode change 100755 => 100644 lib/Resque/Redis.php mode change 100755 => 100644 test/Resque/Tests/DsnTest.php diff --git a/demo/check_status.php b/demo/check_status.php old mode 100755 new mode 100644 diff --git a/demo/queue.php b/demo/queue.php old mode 100755 new mode 100644 diff --git a/lib/Resque.php b/lib/Resque.php old mode 100755 new mode 100644 diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php old mode 100755 new mode 100644 diff --git a/test/Resque/Tests/DsnTest.php b/test/Resque/Tests/DsnTest.php old mode 100755 new mode 100644 From 40d2ec8c77ab85d1e7f218286d5fe2c4409f9ab8 Mon Sep 17 00:00:00 2001 From: Todd Burry Date: Mon, 23 Jun 2014 08:20:23 -0400 Subject: [PATCH 9/9] Make the credis requirements less strict. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since credis has moved forward, but is backwards compatible, resque shouldn’t be so strict towards an old version because other libraries need newer credis features. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fb868bc..6e31daa 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require": { "php": ">=5.3.0", "ext-pcntl": "*", - "colinmollenhour/credis": "1.2.*", + "colinmollenhour/credis": "~1.2", "psr/log": "1.0.0" }, "suggest": {