當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Resque::redis方法代碼示例

本文整理匯總了PHP中Resque::redis方法的典型用法代碼示例。如果您正苦於以下問題:PHP Resque::redis方法的具體用法?PHP Resque::redis怎麽用?PHP Resque::redis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Resque的用法示例。


在下文中一共展示了Resque::redis方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setBackend

	public static function setBackend($server)
	{
		list($host, $port) = explode(':', $server);

		require_once dirname(__FILE__).'/Resque/Redis.php';
		self::$redis = new Resque_Redis($host, $port);
	}
開發者ID:hungnv0789,項目名稱:vhtm,代碼行數:7,代碼來源:Resque.php

示例2: redis

 /**
  * Return an instance of the Resque_Redis class instantiated for Resque.
  *
  * @return Resque_Redis Instance of Resque_Redis.
  */
 public static function redis()
 {
     // Detect when the PID of the current process has changed (from a fork, etc)
     // and force a reconnect to redis.
     $pid = getmypid();
     if (self::$pid !== $pid) {
         self::$redis = null;
         self::$pid = $pid;
     }
     if (!is_null(self::$redis)) {
         return self::$redis;
     }
     $server = self::$redisServer;
     if (empty($server)) {
         $server = 'localhost:6379';
     }
     if (is_array($server)) {
         require_once dirname(__FILE__) . '/Resque/RedisCluster.php';
         self::$redis = new Resque_RedisCluster($server);
     } else {
         if (strpos($server, 'unix:') === false) {
             list($host, $port) = explode(':', $server);
         } else {
             $host = $server;
             $port = null;
         }
         require_once dirname(__FILE__) . '/Resque/Redis.php';
         $redisInstance = new Resque_Redis($host, $port);
         $redisInstance->prefix(self::$namespace);
         self::$redis = $redisInstance;
     }
     self::$redis->select(self::$redisDatabase);
     return self::$redis;
 }
開發者ID:klimis,項目名稱:php-edge,代碼行數:39,代碼來源:Resque.php

示例3: getRedis

 private function getRedis()
 {
     $redis = \Resque::$redis;
     if ($redis === null) {
         $redis = \Resque::redis();
     }
     return $redis;
 }
開發者ID:songhongyu,項目名稱:datecenter,代碼行數:8,代碼來源:QueueController.php

示例4: testRedisExceptionsAreSurfaced

 /**
  * @expectedException Resque_RedisException
  */
 public function testRedisExceptionsAreSurfaced()
 {
     $mockCredis = $this->getMockBuilder('Credis_Client')->setMethods(['connect', '__call'])->getMock();
     $mockCredis->expects($this->any())->method('__call')->will($this->throwException(new CredisException('failure')));
     Resque::setBackend(function ($database) use($mockCredis) {
         return new Resque_Redis('localhost:6379', $database, $mockCredis);
     });
     Resque::redis()->ping();
 }
開發者ID:chrisboulton,項目名稱:php-resque,代碼行數:12,代碼來源:RedisTest.php

示例5: jobs

 /**
  * @return Job[]
  */
 public function jobs()
 {
     $result = \Resque::redis()->lrange('queue:' . $this->name, 0, -1);
     $jobs = [];
     foreach ($result as $job) {
         $jobs[] = (new \Resque_Job($this->name, \json_decode($job, true)))->getInstance();
     }
     return $jobs;
 }
開發者ID:hlgrrnhrdt,項目名稱:laravel-resque,代碼行數:12,代碼來源:Queue.php

示例6: getJobs

 public function getJobs($start = 0, $stop = -1)
 {
     $jobs = \Resque::redis()->lrange('queue:' . $this->name, $start, $stop);
     $result = array();
     foreach ($jobs as $job) {
         $job = new \Resque_Job($this->name, \json_decode($job, true));
         $result[] = $job->getInstance();
     }
     return $result;
 }
開發者ID:janiusus,項目名稱:BCCResqueBundle,代碼行數:10,代碼來源:Queue.php

示例7: peek

 /**
  * Peek
  *
  * @param string $queue The name of the queue
  * @param integer $start
  * @param integer $count
  *
  * @return array List of jobs
  *
  */
 public static function peek($queue, $start = 0, $count = 1000)
 {
     $jobs = \Resque::redis()->lrange('queue:' . $queue, $start, $count);
     $curr_jobs = array();
     if (is_array($jobs)) {
         foreach ($jobs as $job) {
             $curr_jobs[] = json_decode($job, TRUE);
         }
     }
     return $curr_jobs;
 }
開發者ID:neilmillard,項目名稱:fxtrader,代碼行數:21,代碼來源:QueuesAction.php

示例8: requeue

 public static function requeue($id)
 {
     //        item = all(id)
     //        item['retried_at'] = Time.now.rfc2822
     //        Resque.redis.lset(:failed, id, Resque.encode(item))
     //        Job.create(item['queue'], item['payload']['class'], *item['payload']['args'])
     $item = current(self::all($id, 1));
     $item->retried_at = strftime('%a %b %d %H:%M:%S %Z %Y');
     $data = json_encode($item);
     \Resque::redis()->lset('failed', $id, $data);
     \Resque::enqueue($item->queue, $item->payload->class, (array) $item->payload->args[0]);
 }
開發者ID:geoffreytran,項目名稱:zym,代碼行數:12,代碼來源:Redis.php

示例9: setBackend

 /**
  * 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
  * a nested array of servers with host/port pairs.
  */
 public static function setBackend($server, $database = 0)
 {
     if (is_array($server)) {
         require_once dirname(__FILE__) . '/Resque/RedisCluster.php';
         self::$redis = new Resque_RedisCluster($server);
     } else {
         list($host, $port) = explode(':', $server);
         require_once dirname(__FILE__) . '/Resque/Redis.php';
         self::$redis = new Resque_Redis($host, $port);
     }
     self::redis()->select($database);
 }
開發者ID:Rming,項目名稱:novophp,代碼行數:19,代碼來源:Resque.php

示例10: __construct

 /**
  * Initialize a failed job class and save it (where appropriate).
  *
  * @param object $payload Object containing details of the failed job.
  * @param object $exception Instance of the exception that was thrown by the failed job.
  * @param object $worker Instance of Resque_Worker that received the job.
  * @param string $queue The name of the queue the job was fetched from.
  */
 public function __construct($payload, $exception, $worker, $queue)
 {
     $data = new stdClass();
     $data->failed_at = strftime('%a %b %d %H:%M:%S %Z %Y');
     $data->payload = $payload;
     $data->exception = get_class($exception);
     $data->error = $exception->getMessage();
     $data->backtrace = explode("\n", $exception->getTraceAsString());
     $data->worker = (string) $worker;
     $data->queue = $queue;
     $data = json_encode($data);
     Resque::redis()->rpush('failed', $data);
 }
開發者ID:jacques,項目名稱:php-resque,代碼行數:21,代碼來源:Redis.php

示例11: fork

 /**
  * fork() helper method for php-resque that handles issues PHP socket
  * and phpredis have with passing around sockets between child/parent
  * processes.
  *
  * Will close connection to Redis before forking.
  *
  * @return int Return vars as per pcntl_fork()
  */
 public static function fork()
 {
     if (!function_exists('pcntl_fork')) {
         return -1;
     }
     // Close the connection to Redis before forking.
     // This is a workaround for issues phpredis has.
     self::$redis = null;
     $pid = pcntl_fork();
     if ($pid === -1) {
         throw new RuntimeException('Unable to fork child worker.');
     }
     return $pid;
 }
開發者ID:rolies106,項目名稱:yii2resque,代碼行數:23,代碼來源:Resque.php

示例12: startup

 /**
  * Startup callback.
  *
  * Initializes defaults.
  */
 public function startup()
 {
     $resqueLib = Configure::read('CakeResque.Resque.lib');
     $schedulerLib = Configure::read('CakeResque.Scheduler.lib');
     $pluginVendorPath = CakePlugin::path('CakeResque') . 'vendor' . DS;
     if (substr($resqueLib, 0, 1) !== '/') {
         $resqueLib = $pluginVendorPath . $resqueLib;
     }
     $this->_resqueLibrary = realpath($resqueLib) . DS;
     if (substr($schedulerLib, 0, 1) !== '/') {
         $schedulerLib = $pluginVendorPath . $schedulerLib;
     }
     $this->_resqueSchedulerLibrary = realpath($schedulerLib) . DS;
     $this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
     $this->stdout->styles('success', array('text' => 'green'));
     $this->stdout->styles('bold', array('bold' => true));
 }
開發者ID:rchavik,項目名稱:Cake-Resque,代碼行數:22,代碼來源:CakeResqueShell.php

示例13: getJobs

 protected function getJobs()
 {
     $jobs = new ArrayList();
     $resqueJobs = Resque::redis()->lrange('queue:' . $this->Name, 0, -1);
     if (!$resqueJobs) {
         $jobs->push(new ResqueJob(array('Name' => 'null', 'Value' => 'null')));
         return $jobs;
     }
     foreach ($resqueJobs as $idx => $job) {
         $stdClass = json_decode($job);
         if ($stdClass->class === 'CapistranoDeploy' || $stdClass->class === 'DeployJob') {
             $jobs->push(new ResqueJob(array('Name' => $stdClass->class, 'Value' => $stdClass->args[0]->projectName . ':' . $stdClass->args[0]->environment . ' - ' . $stdClass->args[0]->sha)));
         } else {
             $jobs->push(new ResqueJob(array('Name' => $stdClass->class, 'Value' => var_export($stdClass->args[0], true))));
         }
     }
     return $jobs;
 }
開發者ID:adrexia,項目名稱:deploynaut,代碼行數:18,代碼來源:ResqueQueue.php

示例14: get_all_workers

 public static function get_all_workers($queue = NULL)
 {
     $ret = array();
     $workers = Resque::redis()->smembers('workers');
     if (!is_array($workers)) {
         $workers = array();
     }
     foreach ($workers as $workerId) {
         $worker_data = explode(':', $workerId, 4);
         $worker = array();
         $worker['hostname'] = $worker_data[0];
         $worker['queues'] = explode(',', $worker_data[2]);
         $worker['pid'] = $worker_data[1];
         $worker['programname'] = $worker_data[3];
         $worker['workerId'] = $workerId;
         if ($queue && (in_array($queue, $worker['queues']) || in_array("*", $worker['queues'])) || !$queue) {
             $ret[] = $worker;
         }
     }
     return $ret;
 }
開發者ID:timelessmemory,項目名稱:uhkklp,代碼行數:21,代碼來源:ResqueScaler.php

示例15: workerRemoveDead

 public function workerRemoveDead($user)
 {
     $this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
     $workers = $this->ResqueStatus->getWorkers();
     $this->Log = ClassRegistry::init('Log');
     if (function_exists('posix_getpwuid')) {
         $currentUser = posix_getpwuid(posix_geteuid());
         $currentUser = $currentUser['name'];
     } else {
         $currentUser = trim(shell_exec('whoami'));
     }
     foreach ($workers as $pid => $worker) {
         if (!is_numeric($pid)) {
             throw new MethodNotAllowedException('Non numeric PID found!');
         }
         $pidTest = substr_count(trim(shell_exec('ps -p ' . $pid)), PHP_EOL) > 0 ? true : false;
         if ($worker['user'] == $currentUser && !$pidTest) {
             $this->ResqueStatus->removeWorker($pid);
             $this->Log->create();
             $this->Log->save(array('org' => $user['org'], 'model' => 'User', 'model_id' => $user['id'], 'email' => $user['email'], 'action' => 'remove_dead_workers', 'user_id' => $user['id'], 'title' => 'Removing a dead worker.', 'change' => 'Removind dead worker data. Worker was of type ' . $worker['queue'] . ' with pid ' . $pid));
         }
     }
 }
開發者ID:firebitsbr,項目名稱:MISP,代碼行數:23,代碼來源:Server.php


注:本文中的Resque::redis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。