예제 #1
0
 /**
  * Create the given connection by name.
  *
  * @param  string  $name
  * @return Illuminate\Redis\Database
  */
 protected function createConnection($name)
 {
     $config = $this->getConfig($name);
     $connection = new Database($config['host'], $config['port'], $config['database']);
     $connection->connect();
     return $connection;
 }
예제 #2
0
 public function __construct(SessionManager $manager, Database $db)
 {
     parent::__construct($manager);
     $this->key = env('COMMON_SESSION');
     $this->redis = $db->connection('common');
     if ($this->redis === null) {
         throw new ResourceNotFoundException('Redis Common Connection is not exists.');
     }
 }
예제 #3
0
 /**
  * @param Update $update
  * @return bool
  */
 public function exists(Update $update)
 {
     if (!$this->redis->exists($update->getMessage()->getChat()->getId())) {
         return false;
     }
     return true;
 }
 /**
  * @param $group
  */
 protected function deleteCacheGroup($group)
 {
     $keys = $this->redis->keys($group . '*');
     if (!empty($keys)) {
         $this->redis->del($keys);
     }
 }
예제 #5
0
 public function testDelete()
 {
     $job = new RedisQueueIntegrationTestJob(30);
     $this->queue->push($job);
     /** @var RedisJob $redisJob */
     $redisJob = $this->queue->pop();
     $redisJob->delete();
     $this->assertEquals(0, $this->redis->connection()->zcard('queues:default:delayed'));
     $this->assertEquals(0, $this->redis->connection()->zcard('queues:default:reserved'));
     $this->assertEquals(0, $this->redis->connection()->llen('queues:default'));
     $this->assertNull($this->queue->pop());
 }
예제 #6
0
 /**
  * Run a command against the Redis database.
  *
  * @param  string  $method
  * @param  array  $args
  * @return mixed
  */
 public final function command($method, array $args = [])
 {
     if (in_array(strtolower($method), array_keys($this->storeEncoded))) {
         $values = $this->storeEncoded[strtolower($method)];
         $from = array_get($values, 'from', 0);
         $to = array_get($values, 'to', max(0, count($args) - 1));
         for ($i = $from; $i <= $to; $i++) {
             $args[$i] = $this->encode($args[$i]);
         }
     }
     if ($method == 'mset' || $method == 'msetnx') {
         if (count($args) === 1 && is_array($args[0])) {
             foreach ($args[0] as $k => $v) {
                 $args[0][$k] = $this->encode($v);
             }
         } else {
             foreach ($args as $k => $v) {
                 if ($k % 2 != 0) {
                     $args[$k] = $this->encode($v);
                 }
             }
         }
     }
     if ($method == 'zadd') {
         if (is_array(end($args))) {
             foreach (array_pop($args) as $k => $v) {
                 $args[][$k] = $this->encode($v);
             }
         } else {
             foreach ($arguments as $k => $v) {
                 if ($k !== 0 && $k % 2 == 0) {
                     $arguments[$k] = $this->encode($v);
                 }
             }
         }
     }
     if (in_array(strtolower($method), $this->returnDecoded)) {
         $result = parent::command($method, $args);
         if (is_array($result)) {
             return array_map(function ($value) {
                 return $this->decode($value);
             }, $result);
         }
         return $this->decode($result);
     }
     return parent::command($method, $args);
 }
예제 #7
0
 /**
  * Migrate the delayed jobs that are ready to the regular queue.
  *
  * @param  string  $from
  * @param  string  $to
  * @return void
  */
 public function migrateExpiredJobs($from, $to)
 {
     $options = ['cas' => true, 'watch' => $from, 'retry' => 10];
     $this->redis->transaction($options, function ($transaction) use($from, $to) {
         // First we need to get all of jobs that have expired based on the current time
         // so that we can push them onto the main queue. After we get them we simply
         // remove them from this "delay" queues. All of this within a transaction.
         $jobs = $this->getExpiredJobs($transaction, $from, $time = $this->getTime());
         // If we actually found any jobs, we will remove them from the old queue and we
         // will insert them onto the new (ready) "queue". This means they will stand
         // ready to be processed by the queue worker whenever their turn comes up.
         if (count($jobs) > 0) {
             $this->removeExpiredJobs($transaction, $from, $time);
             $this->pushExpiredJobsOntoNewQueue($transaction, $to, $jobs);
         }
     });
 }
예제 #8
0
 /**
  * Remove an item with a given key, index or value.
  *
  * @param  string  $key
  * @param  string  $value
  * @param  string  $type
  * @return bool
  */
 public function remove($key, $value, $type = null)
 {
     if (is_null($type)) {
         $type = $this->type($key);
     }
     switch ($type) {
         case 'list':
             $key = str_replace(':queued', '', $key);
             $random = Str::quickRandom(64);
             $this->database->lset($key, $value, $random);
             return $this->database->lrem($key, 1, $random);
         case 'zset':
             return $this->database->zrem($key, $value);
         default:
             throw new UnexpectedValueException("Unable to delete {$value} from {$key}. List type {$type} not supported.");
     }
 }
 /**
  * Get the Redis connection instance.
  *
  * @return \Predis\ClientInterface
  */
 public function connection()
 {
     return $this->redis->connection($this->connection);
 }
예제 #10
0
 /**
  * Run a command against the Redis database.
  *
  * @param string $method
  * @param array $parameters
  * @return mixed 
  * @static 
  */
 public static function command($method, $parameters = array())
 {
     return \Illuminate\Redis\Database::command($method, $parameters);
 }
예제 #11
0
 /**
  * Get the connection for the queue.
  *
  * @return \Predis\ClientInterface
  */
 protected function getConnection()
 {
     return $this->redis->connection($this->connection);
 }
예제 #12
0
 /**
  * Subscribe to a set of given channels with wildcards.
  *
  * @param array|string $channels
  * @param \Closure $callback
  * @param string $connection
  * @return void 
  * @static 
  */
 public static function psubscribe($channels, $callback, $connection = null)
 {
     \Illuminate\Redis\Database::psubscribe($channels, $callback, $connection);
 }
예제 #13
0
 /**
  * Remove all items from the cache.
  *
  * @return void
  */
 public function flush()
 {
     $this->redis->flushdb();
 }
 /**
  * Remove the delayed jobs that are ready for processing.
  *
  * @param  string  $queue
  * @param  int     $time
  * @return void
  */
 protected function removeExpiredJobs($queue, $time)
 {
     $this->redis->zremrangebyscore($queue, '-inf', $time);
 }
 function __construct(RedisDatabase $redis)
 {
     $this->redis = $redis->connection();
 }
예제 #16
0
 /**
  * Remove all items from the cache.
  *
  * @return void
  */
 protected function flushItems()
 {
     $this->redis->flushdb();
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(array $server)
 {
     parent::__construct($server);
 }