Author: Daniele Alessandri (suppakilla@gmail.com)
Inheritance: implements Predis\ClientContextInterface
コード例 #1
0
ファイル: RedisQueue.php プロジェクト: rodrigopbel/ong
 /**
  * Remove the expired jobs from a given queue.
  *
  * @param  \Predis\Transaction\MultiExec  $transaction
  * @param  string  $from
  * @param  int  $time
  * @return void
  */
 protected function removeExpiredJobs($transaction, $from, $time)
 {
     $transaction->multi();
     $transaction->zremrangebyscore($from, '-inf', $time);
 }
コード例 #2
0
ファイル: predis.php プロジェクト: sohel4r/wordpress_4_1_1
 /**
  * Actual transaction context initializer method.
  *
  * @param array $options  Options for the context.
  * @param mixed $callable Optional callable used to execute the context.
  *
  * @return MultiExecTransaction|array
  */
 protected function createTransaction(array $options = null, $callable = null)
 {
     $transaction = new MultiExecTransaction($this, $options);
     if (isset($callable)) {
         return $transaction->execute($callable);
     }
     return $transaction;
 }
コード例 #3
0
ファイル: ObjectRepository.php プロジェクト: tystr/redis-orm
 /**
  * @param ReflectionClass $reflClass
  * @param object          $object
  * @param string          $propertyName
  * @param Metadata        $metadata
  * @param array           $newData
  * @param MultiExec       $transaction
  */
 protected function handleSortedIndex(ReflectionClass $reflClass, $object, $propertyName, $keyName, Metadata $metadata, array $newData, $transaction)
 {
     $property = $reflClass->getProperty($propertyName);
     $property->setAccessible(true);
     $mapping = $metadata->getPropertyMapping($propertyName);
     if (!isset($newData[$mapping['name']]) || null === $newData[$mapping['name']]) {
         $transaction->zrem($this->keyNamingStrategy->getKeyName(array($keyName, $newData[$mapping['name']])), $this->getIdForClass($object, $metadata));
         return;
     }
     $transaction->zadd($this->keyNamingStrategy->getKeyName(array($keyName)), $newData[$mapping['name']], $this->getIdForClass($object, $metadata));
 }
コード例 #4
0
ファイル: RateLimit.php プロジェクト: Pouix/SncRedisBundle
 /**
  * Adds the commands needed for the count function.
  *
  * @param MultiExec $multi   A MultiExec instance
  * @param string    $subject A unique identifier, for example a session id or an IP
  * @param int       $bucket  Bucket
  * @param int       $count   Count
  */
 private function addMultiExecCount(MultiExec $multi, $subject, $bucket, $count)
 {
     // Get the counts from the previous `$count` buckets
     $multi->hget($subject, $bucket);
     while ($count--) {
         $multi->hget($subject, (--$bucket + $this->bucketCount) % $this->bucketCount);
     }
 }
コード例 #5
0
 /**
  * @group disconnected
  * @expectedException \Predis\Response\ServerException
  * @expectedExceptionMessage ERR simulated failure on EXEC
  */
 public function testExceptionsOptionDoesNotAffectTransactionControlCommands()
 {
     $connection = $this->getMockedConnection(function (CommandInterface $command) {
         switch ($command->getId()) {
             case 'MULTI':
                 return true;
             case 'EXEC':
                 return new Response\Error('ERR simulated failure on EXEC');
             default:
                 return new Response\Status('QUEUED');
         }
     });
     $client = new Client($connection, array('exceptions' => false));
     $tx = new MultiExec($client);
     $tx->multi()->echo('test')->exec();
 }
コード例 #6
0
 /**
  * Remove stale elements at the top of the queue and return the first real entry
  *
  * When data expires, it still leaves a queue entry linking to its
  * correlation ID.  Clear any of these stale entries at the head of
  * the queue.
  *
  * Note that we run this from inside a transaction, to make it less
  * likely that we'll hit a race condition.
  *
  * @param MultiExec $tx transaction we're working within.
  *
  * @return string|null Top element's key, or null if the queue is empty.
  */
 public function peekWithCleanup(MultiExec $tx)
 {
     for (;;) {
         // Look up the first element in the FIFO ordering.
         $values = $tx->zrange(Predis::FIFO_INDEX, 0, 0);
         if ($values) {
             // Use that value as a key into the key-value block.
             $key = $values[0];
             $exists = $tx->exists($key);
             if (!$exists) {
                 // If the data is missing, then remove from the FIFO index.
                 $tx->zrem(Predis::FIFO_INDEX, $key);
             } else {
                 return $key;
             }
         } else {
             break;
         }
     }
     return null;
 }