@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | { |
| 11 | 11 | const VERSION = '1.2'; |
| 12 | 12 | |
| 13 | - const DEFAULT_INTERVAL = 5; |
|
| 13 | + const DEFAULT_INTERVAL = 5; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * @var Resque_Redis Instance of Resque_Redis that talks to redis. |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | protected static $redisDatabase = 0; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var string auth of Redis database |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var string auth of Redis database |
|
| 33 | + */ |
|
| 34 | 34 | protected static $auth; |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * and returns a Resque_Redis instance, or |
| 43 | 43 | * a nested array of servers with host/port pairs. |
| 44 | 44 | * @param int $database |
| 45 | - * @param string $auth |
|
| 45 | + * @param string $auth |
|
| 46 | 46 | */ |
| 47 | 47 | public static function setBackend($server, $database = 0, $auth = null) |
| 48 | 48 | { |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | if (!empty(self::$auth)) { |
| 73 | - self::$redis->auth(self::$auth); |
|
| 74 | - } |
|
| 73 | + self::$redis->auth(self::$auth); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | return self::$redis; |
| 77 | 77 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public static function pop($queue) |
| 135 | 135 | { |
| 136 | - $item = self::redis()->lpop('queue:' . $queue); |
|
| 136 | + $item = self::redis()->lpop('queue:' . $queue); |
|
| 137 | 137 | |
| 138 | 138 | if(!$item) { |
| 139 | 139 | return; |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | public static function dequeue($queue, $items = Array()) |
| 153 | 153 | { |
| 154 | - if(count($items) > 0) { |
|
| 154 | + if(count($items) > 0) { |
|
| 155 | 155 | return self::removeItems($queue, $items); |
| 156 | - } else { |
|
| 156 | + } else { |
|
| 157 | 157 | return self::removeList($queue); |
| 158 | - } |
|
| 158 | + } |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public static function removeQueue($queue) |
| 168 | 168 | { |
| 169 | - $num = self::removeList($queue); |
|
| 170 | - self::redis()->srem('queues', $queue); |
|
| 171 | - return $num; |
|
| 169 | + $num = self::removeList($queue); |
|
| 170 | + self::redis()->srem('queues', $queue); |
|
| 171 | + return $num; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -181,28 +181,28 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | public static function blpop(array $queues, $timeout) |
| 183 | 183 | { |
| 184 | - $list = array(); |
|
| 185 | - foreach($queues AS $queue) { |
|
| 184 | + $list = array(); |
|
| 185 | + foreach($queues AS $queue) { |
|
| 186 | 186 | $list[] = 'queue:' . $queue; |
| 187 | - } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - $item = self::redis()->blpop($list, (int)$timeout); |
|
| 189 | + $item = self::redis()->blpop($list, (int)$timeout); |
|
| 190 | 190 | |
| 191 | - if(!$item) { |
|
| 191 | + if(!$item) { |
|
| 192 | 192 | return; |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Normally the Resque_Redis class returns queue names without the prefix |
|
| 197 | - * But the blpop is a bit different. It returns the name as prefix:queue:name |
|
| 198 | - * So we need to strip off the prefix:queue: part |
|
| 199 | - */ |
|
| 200 | - $queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:')); |
|
| 195 | + /** |
|
| 196 | + * Normally the Resque_Redis class returns queue names without the prefix |
|
| 197 | + * But the blpop is a bit different. It returns the name as prefix:queue:name |
|
| 198 | + * So we need to strip off the prefix:queue: part |
|
| 199 | + */ |
|
| 200 | + $queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:')); |
|
| 201 | 201 | |
| 202 | - return array( |
|
| 202 | + return array( |
|
| 203 | 203 | 'queue' => $queue, |
| 204 | 204 | 'payload' => json_decode($item[1], true) |
| 205 | - ); |
|
| 205 | + ); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | while (!$finished) { |
| 331 | 331 | $string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() .$originalQueue); |
| 332 | 332 | if (empty($string)) { |
| 333 | - $finished = true; |
|
| 333 | + $finished = true; |
|
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
@@ -353,29 +353,29 @@ discard block |
||
| 353 | 353 | */ |
| 354 | 354 | private static function matchItem($string, $items) |
| 355 | 355 | { |
| 356 | - $decoded = json_decode($string, true); |
|
| 356 | + $decoded = json_decode($string, true); |
|
| 357 | 357 | |
| 358 | - foreach($items as $key => $val) { |
|
| 358 | + foreach($items as $key => $val) { |
|
| 359 | 359 | # class name only ex: item[0] = ['class'] |
| 360 | 360 | if (is_numeric($key)) { |
| 361 | - if($decoded['class'] == $val) { |
|
| 361 | + if($decoded['class'] == $val) { |
|
| 362 | 362 | return true; |
| 363 | - } |
|
| 363 | + } |
|
| 364 | 364 | # class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}] |
| 365 | 365 | } elseif (is_array($val)) { |
| 366 | - $decodedArgs = (array)$decoded['args'][0]; |
|
| 367 | - if ($decoded['class'] == $key && |
|
| 366 | + $decodedArgs = (array)$decoded['args'][0]; |
|
| 367 | + if ($decoded['class'] == $key && |
|
| 368 | 368 | count($decodedArgs) > 0 && count(array_diff($decodedArgs, $val)) == 0) { |
| 369 | 369 | return true; |
| 370 | 370 | } |
| 371 | 371 | # class name with ID, example: item[0] = ['class' => 'id'] |
| 372 | 372 | } else { |
| 373 | - if ($decoded['class'] == $key && $decoded['id'] == $val) { |
|
| 373 | + if ($decoded['class'] == $key && $decoded['id'] == $val) { |
|
| 374 | 374 | return true; |
| 375 | - } |
|
| 375 | + } |
|
| 376 | 376 | } |
| 377 | - } |
|
| 378 | - return false; |
|
| 377 | + } |
|
| 378 | + return false; |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -388,9 +388,9 @@ discard block |
||
| 388 | 388 | */ |
| 389 | 389 | private static function removeList($queue) |
| 390 | 390 | { |
| 391 | - $counter = self::size($queue); |
|
| 392 | - $result = self::redis()->del('queue:' . $queue); |
|
| 393 | - return ($result == 1) ? $counter : 0; |
|
| 391 | + $counter = self::size($queue); |
|
| 392 | + $result = self::redis()->del('queue:' . $queue); |
|
| 393 | + return ($result == 1) ? $counter : 0; |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /* |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | private static $processPrefix = 'resque'; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface |
|
| 21 | - */ |
|
| 20 | + * @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface |
|
| 21 | + */ |
|
| 22 | 22 | public $logger; |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -61,30 +61,30 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | private $child = null; |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Instantiate a new worker, given a list of queues that it should be working |
|
| 66 | - * on. The list of queues should be supplied in the priority that they should |
|
| 67 | - * be checked for jobs (first come, first served) |
|
| 68 | - * |
|
| 69 | - * Passing a single '*' allows the worker to work on all queues in alphabetical |
|
| 70 | - * order. You can easily add new queues dynamically and have them worked on using |
|
| 71 | - * this method. |
|
| 72 | - * |
|
| 73 | - * @param string|array $queues String with a single queue name, array with multiple. |
|
| 74 | - */ |
|
| 75 | - public function __construct($queues) |
|
| 76 | - { |
|
| 77 | - $this->logger = new Resque_Log(); |
|
| 64 | + /** |
|
| 65 | + * Instantiate a new worker, given a list of queues that it should be working |
|
| 66 | + * on. The list of queues should be supplied in the priority that they should |
|
| 67 | + * be checked for jobs (first come, first served) |
|
| 68 | + * |
|
| 69 | + * Passing a single '*' allows the worker to work on all queues in alphabetical |
|
| 70 | + * order. You can easily add new queues dynamically and have them worked on using |
|
| 71 | + * this method. |
|
| 72 | + * |
|
| 73 | + * @param string|array $queues String with a single queue name, array with multiple. |
|
| 74 | + */ |
|
| 75 | + public function __construct($queues) |
|
| 76 | + { |
|
| 77 | + $this->logger = new Resque_Log(); |
|
| 78 | 78 | |
| 79 | - if(!is_array($queues)) { |
|
| 80 | - $queues = array($queues); |
|
| 81 | - } |
|
| 79 | + if(!is_array($queues)) { |
|
| 80 | + $queues = array($queues); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $this->queues = $queues; |
|
| 84 | - $this->hostname = php_uname('n'); |
|
| 83 | + $this->queues = $queues; |
|
| 84 | + $this->hostname = php_uname('n'); |
|
| 85 | 85 | |
| 86 | - $this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues); |
|
| 87 | - } |
|
| 86 | + $this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * Set the process prefix of the workers to the given prefix string. |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | $this->updateProcLine('Starting'); |
| 167 | 167 | $this->startup(); |
| 168 | 168 | |
| 169 | - if(function_exists('pcntl_signal_dispatch')) { |
|
| 170 | - pcntl_signal_dispatch(); |
|
| 171 | - } |
|
| 169 | + if(function_exists('pcntl_signal_dispatch')) { |
|
| 170 | + pcntl_signal_dispatch(); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | while(true) { |
| 174 | 174 | if($this->shutdown) { |
@@ -177,14 +177,14 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | // is redis still alive? |
| 179 | 179 | try { |
| 180 | - if (Resque::redis()->ping() === false) { |
|
| 181 | - throw new CredisException('redis ping() failed'); |
|
| 182 | - } |
|
| 180 | + if (Resque::redis()->ping() === false) { |
|
| 181 | + throw new CredisException('redis ping() failed'); |
|
| 182 | + } |
|
| 183 | 183 | } catch (CredisException $e) { |
| 184 | - $this->logger->log(Psr\Log\LogLevel::ERROR, 'redis went away. trying to reconnect'); |
|
| 185 | - Resque::$redis = null; |
|
| 186 | - usleep($interval * 1000000); |
|
| 187 | - continue; |
|
| 184 | + $this->logger->log(Psr\Log\LogLevel::ERROR, 'redis went away. trying to reconnect'); |
|
| 185 | + Resque::$redis = null; |
|
| 186 | + usleep($interval * 1000000); |
|
| 187 | + continue; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // Attempt to find and reserve a job |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | // Wait until the child process finishes before continuing |
| 260 | 260 | while (pcntl_wait($status, WNOHANG) === 0) { |
| 261 | 261 | if(function_exists('pcntl_signal_dispatch')) { |
| 262 | - pcntl_signal_dispatch(); |
|
| 263 | - } |
|
| 262 | + pcntl_signal_dispatch(); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | 265 | // Pause for a half a second to conserve system resources |
| 266 | 266 | usleep(500000); |
@@ -336,11 +336,11 @@ discard block |
||
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | if($blocking === true) { |
| 339 | - if(empty($queues)){ |
|
| 340 | - $this->logger->log(Psr\Log\LogLevel::INFO, 'No queue was found, sleeping for {interval}', array('interval' => $timeout)); |
|
| 341 | - usleep($timeout * 1000000); |
|
| 342 | - return false; |
|
| 343 | - } |
|
| 339 | + if(empty($queues)){ |
|
| 340 | + $this->logger->log(Psr\Log\LogLevel::INFO, 'No queue was found, sleeping for {interval}', array('interval' => $timeout)); |
|
| 341 | + usleep($timeout * 1000000); |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 344 | 344 | $job = Resque_Job::reserveBlocking($queues, $timeout); |
| 345 | 345 | if($job) { |
| 346 | 346 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue)); |
@@ -212,8 +212,7 @@ discard block |
||
| 212 | 212 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Sleeping for {interval}', array('interval' => $interval)); |
| 213 | 213 | if($this->paused) { |
| 214 | 214 | $this->updateProcLine('Paused'); |
| 215 | - } |
|
| 216 | - else { |
|
| 215 | + } else { |
|
| 217 | 216 | $this->updateProcLine('Waiting'); |
| 218 | 217 | } |
| 219 | 218 | |
@@ -272,8 +271,7 @@ discard block |
||
| 272 | 271 | $job->fail(new Resque_Job_DirtyExitException( |
| 273 | 272 | 'Job exited with exit code ' . $exitStatus |
| 274 | 273 | )); |
| 275 | - } |
|
| 276 | - else |
|
| 274 | + } else |
|
| 277 | 275 | { |
| 278 | 276 | if (in_array($job->getStatus(), array(Resque_Job_Status::STATUS_WAITING, Resque_Job_Status::STATUS_RUNNING))) |
| 279 | 277 | { |
@@ -301,13 +299,11 @@ discard block |
||
| 301 | 299 | try { |
| 302 | 300 | Resque_Event::trigger('afterFork', $job); |
| 303 | 301 | $result = $job->perform(); |
| 304 | - } |
|
| 305 | - catch(Exception $e) { |
|
| 302 | + } catch(Exception $e) { |
|
| 306 | 303 | $this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {exception}', array('job' => $job, 'exception' => $e)); |
| 307 | 304 | $job->fail($e); |
| 308 | 305 | return; |
| 309 | - } |
|
| 310 | - catch(Error $e) { |
|
| 306 | + } catch(Error $e) { |
|
| 311 | 307 | $this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {exception}', array('job' => $job, 'exception' => $e)); |
| 312 | 308 | $job->fail($e); |
| 313 | 309 | return; |
@@ -405,8 +401,7 @@ discard block |
||
| 405 | 401 | $processTitle = static::$processPrefix . '-' . Resque::VERSION . ' (' . implode(',', $this->queues) . '): ' . $status; |
| 406 | 402 | if(function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') { |
| 407 | 403 | cli_set_process_title($processTitle); |
| 408 | - } |
|
| 409 | - else if(function_exists('setproctitle')) { |
|
| 404 | + } else if(function_exists('setproctitle')) { |
|
| 410 | 405 | setproctitle($processTitle); |
| 411 | 406 | } |
| 412 | 407 | } |
@@ -496,8 +491,7 @@ discard block |
||
| 496 | 491 | $this->logger->log(Psr\Log\LogLevel::DEBUG, 'Child {child} found, killing.', array('child' => $this->child)); |
| 497 | 492 | posix_kill($this->child, SIGKILL); |
| 498 | 493 | $this->child = null; |
| 499 | - } |
|
| 500 | - else { |
|
| 494 | + } else { |
|
| 501 | 495 | $this->logger->log(Psr\Log\LogLevel::INFO, 'Child {child} not found, restarting.', array('child' => $this->child)); |
| 502 | 496 | $this->shutdown(); |
| 503 | 497 | } |
@@ -542,8 +536,7 @@ discard block |
||
| 542 | 536 | $line = preg_replace('/\s+/m', ' ', $line); |
| 543 | 537 | list(,,$pids[]) = explode(' ', trim($line), 3); |
| 544 | 538 | } |
| 545 | - } |
|
| 546 | - else { |
|
| 539 | + } else { |
|
| 547 | 540 | exec('ps -A -o pid,args | grep [r]esque', $cmdOutput); |
| 548 | 541 | foreach($cmdOutput as $line) { |
| 549 | 542 | list($pids[],) = explode(' ', trim($line), 2); |
@@ -628,8 +621,7 @@ discard block |
||
| 628 | 621 | $job = Resque::redis()->get('worker:' . $this); |
| 629 | 622 | if(!$job) { |
| 630 | 623 | return array(); |
| 631 | - } |
|
| 632 | - else { |
|
| 624 | + } else { |
|
| 633 | 625 | return json_decode($job, true); |
| 634 | 626 | } |
| 635 | 627 | } |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | const STATUS_COMPLETE = 4; |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * @var string The prefix of the job status id. |
|
| 18 | - */ |
|
| 17 | + * @var string The prefix of the job status id. |
|
| 18 | + */ |
|
| 19 | 19 | private $prefix; |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -143,33 +143,33 @@ discard block |
||
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * Fetch the last update timestamp of the job being monitored. |
|
| 147 | - * |
|
| 148 | - * @return mixed False if the job is not being monitored, otherwise the |
|
| 146 | + * Fetch the last update timestamp of the job being monitored. |
|
| 147 | + * |
|
| 148 | + * @return mixed False if the job is not being monitored, otherwise the |
|
| 149 | 149 | * update timestamp. |
| 150 | - */ |
|
| 150 | + */ |
|
| 151 | 151 | public function updated() |
| 152 | 152 | { |
| 153 | 153 | return $this->fetch('updated'); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | - * Fetch the start timestamp of the job being monitored. |
|
| 158 | - * |
|
| 159 | - * @return mixed False if the job is not being monitored, otherwise the |
|
| 157 | + * Fetch the start timestamp of the job being monitored. |
|
| 158 | + * |
|
| 159 | + * @return mixed False if the job is not being monitored, otherwise the |
|
| 160 | 160 | * start timestamp. |
| 161 | - */ |
|
| 161 | + */ |
|
| 162 | 162 | public function started() |
| 163 | 163 | { |
| 164 | 164 | return $this->fetch('started'); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | - * Fetch the result of the job being monitored. |
|
| 169 | - * |
|
| 170 | - * @return mixed False if the job is not being monitored, otherwise the result |
|
| 171 | - * as mixed |
|
| 172 | - */ |
|
| 168 | + * Fetch the result of the job being monitored. |
|
| 169 | + * |
|
| 170 | + * @return mixed False if the job is not being monitored, otherwise the result |
|
| 171 | + * as mixed |
|
| 172 | + */ |
|
| 173 | 173 | public function result() |
| 174 | 174 | { |
| 175 | 175 | return $this->fetch('result'); |
@@ -194,11 +194,11 @@ discard block |
||
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | - * Fetch a value from the status packet for the job being monitored. |
|
| 198 | - * |
|
| 199 | - * @return mixed False if the status is not being monitored, otherwise the |
|
| 200 | - * requested value from the status packet. |
|
| 201 | - */ |
|
| 197 | + * Fetch a value from the status packet for the job being monitored. |
|
| 198 | + * |
|
| 199 | + * @return mixed False if the status is not being monitored, otherwise the |
|
| 200 | + * requested value from the status packet. |
|
| 201 | + */ |
|
| 202 | 202 | protected function fetch($value = null) |
| 203 | 203 | { |
| 204 | 204 | if(!$this->isTracking()) { |
@@ -98,10 +98,10 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | public static function prefix($namespace) |
| 100 | 100 | { |
| 101 | - if (substr($namespace, -1) !== ':' && $namespace != '') { |
|
| 102 | - $namespace .= ':'; |
|
| 103 | - } |
|
| 104 | - self::$defaultNamespace = $namespace; |
|
| 101 | + if (substr($namespace, -1) !== ':' && $namespace != '') { |
|
| 102 | + $namespace .= ':'; |
|
| 103 | + } |
|
| 104 | + self::$defaultNamespace = $namespace; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * DSN-supplied value will be used instead and this parameter is ignored. |
| 111 | 111 | * @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you |
| 112 | 112 | */ |
| 113 | - public function __construct($server, $database = null, $client = null) |
|
| 113 | + public function __construct($server, $database = null, $client = null) |
|
| 114 | 114 | { |
| 115 | 115 | try { |
| 116 | 116 | if (is_object($client)) { |
@@ -258,16 +258,16 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | public static function getPrefix() |
| 260 | 260 | { |
| 261 | - return self::$defaultNamespace; |
|
| 261 | + return self::$defaultNamespace; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | public static function removePrefix($string) |
| 265 | 265 | { |
| 266 | - $prefix=self::getPrefix(); |
|
| 266 | + $prefix=self::getPrefix(); |
|
| 267 | 267 | |
| 268 | - if (substr($string, 0, strlen($prefix)) == $prefix) { |
|
| 269 | - $string = substr($string, strlen($prefix), strlen($string) ); |
|
| 270 | - } |
|
| 271 | - return $string; |
|
| 268 | + if (substr($string, 0, strlen($prefix)) == $prefix) { |
|
| 269 | + $string = substr($string, strlen($prefix), strlen($string) ); |
|
| 270 | + } |
|
| 271 | + return $string; |
|
| 272 | 272 | } |
| 273 | 273 | } |
@@ -115,14 +115,11 @@ discard block |
||
| 115 | 115 | try { |
| 116 | 116 | if (is_object($client)) { |
| 117 | 117 | $this->driver = $client; |
| 118 | - } |
|
| 119 | - elseif (is_object($server)) { |
|
| 118 | + } elseif (is_object($server)) { |
|
| 120 | 119 | $this->driver = $server; |
| 121 | - } |
|
| 122 | - elseif (is_array($server)) { |
|
| 120 | + } elseif (is_array($server)) { |
|
| 123 | 121 | $this->driver = new Credis_Cluster($server); |
| 124 | - } |
|
| 125 | - else { |
|
| 122 | + } else { |
|
| 126 | 123 | list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server); |
| 127 | 124 | // $user is not used, only $password |
| 128 | 125 | |
@@ -147,8 +144,7 @@ discard block |
||
| 147 | 144 | if ($database !== null) { |
| 148 | 145 | $this->driver->select($database); |
| 149 | 146 | } |
| 150 | - } |
|
| 151 | - catch(CredisException $e) { |
|
| 147 | + } catch(CredisException $e) { |
|
| 152 | 148 | throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e); |
| 153 | 149 | } |
| 154 | 150 | } |
@@ -243,15 +239,13 @@ discard block |
||
| 243 | 239 | foreach ($args[0] AS $i => $v) { |
| 244 | 240 | $args[0][$i] = self::$defaultNamespace . $v; |
| 245 | 241 | } |
| 246 | - } |
|
| 247 | - else { |
|
| 242 | + } else { |
|
| 248 | 243 | $args[0] = self::$defaultNamespace . $args[0]; |
| 249 | 244 | } |
| 250 | 245 | } |
| 251 | 246 | try { |
| 252 | 247 | return $this->driver->__call($name, $args); |
| 253 | - } |
|
| 254 | - catch (CredisException $e) { |
|
| 248 | + } catch (CredisException $e) { |
|
| 255 | 249 | throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e); |
| 256 | 250 | } |
| 257 | 251 | } |