Example #1
0
 /**
  * @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));
 }
 /**
  * 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;
 }