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


PHP Client::zcard方法代碼示例

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


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

示例1: count

 /**
  * {@inheritDoc}
  */
 public function count(array $sources)
 {
     call_user_func_array([$this->redis, 'zunionstore'], array_merge([$key = sha1(microtime()), count($sources)], array_map(function ($source) {
         return "aggregator:sources:{$source}";
     }, $sources)));
     $count = $this->redis->zcard($key);
     $this->redis->del($key);
     return $count;
 }
開發者ID:nonconforme,項目名稱:aggregator,代碼行數:12,代碼來源:RedisAggregator.php

示例2: findIdsBy

 /**
  * @param CriteriaInterface $criteria
  *
  * @throws InvalidCriteriaException
  *
  * @return array
  */
 public function findIdsBy(CriteriaInterface $criteria, $countOnly = false)
 {
     $resultKey = $this->getResults($criteria->getRestrictions(), self::OP_INTERSECT);
     if ($countOnly) {
         return $this->redis->zcard($resultKey);
     }
     return $this->redis->zrange($resultKey, 0, -1);
 }
開發者ID:tystr,項目名稱:redis-orm,代碼行數:15,代碼來源:ObjectRepository.php

示例3: findIdsBy

 /**
  * @param CriteriaInterface $criteria
  * @throws InvalidCriteriaException
  * @return array
  */
 public function findIdsBy(CriteriaInterface $criteria, $countOnly = false)
 {
     $keys = array();
     $rangeQueries = array();
     $restrictions = $criteria->getRestrictions();
     if ($restrictions->count() == 0) {
         throw new InvalidCriteriaException('Criteria must have at least 1 restriction, found 0.');
     }
     foreach ($restrictions as $restriction) {
         if ($restriction instanceof EqualToInterface) {
             $keys[] = $this->keyNamingStrategy->getKeyName(array($restriction->getKey(), $restriction->getValue()));
         } elseif ($restriction instanceof LessThanInterface) {
             $key = $restriction->getKey();
             $query = isset($rangeQueries[$key]) ? $rangeQueries[$key] : new ZRangeByScore($key);
             $query->setMax($restriction->getValue());
             $rangeQueries[$key] = $query;
         } elseif ($restriction instanceof GreaterThanInterface) {
             $key = $restriction->getKey();
             $query = isset($rangeQueries[$key]) ? $rangeQueries[$key] : new ZRangeByScore($key);
             $query->setMin($restriction->getValue());
             $rangeQueries[$key] = $query;
         } elseif ($restriction instanceof LessThanXDaysAgoInterface) {
             $key = $restriction->getKey();
             $query = isset($rangeQueries[$key]) ? $rangeQueries[$key] : new ZRangeByScore($key);
             $value = strtotime($restriction->getValue());
             if (false === $value) {
                 throw new InvalidRestrictionValue(sprintf('The value "%s" is not a valid format. Must be similar to "5 days ago" or "1 month 15 days ago".', $restriction->getValue()));
             }
             $date = DateTime::createFromFormat('U', $value);
             $date->setTime(0, 0, 0);
             $query->setMin($date->format('U'));
             $rangeQueries[$key] = $query;
         } elseif ($restriction instanceof GreaterThanXDaysAgoInterface) {
             $key = $restriction->getKey();
             $query = isset($rangeQueries[$key]) ? $rangeQueries[$key] : new ZRangeByScore($key);
             $value = strtotime($restriction->getValue());
             if (false === $value) {
                 throw new InvalidRestrictionValue(sprintf('The value "%s" is not a valid format. Must be similar to "5 days ago" or "1 month 15 days ago".', $restriction->getValue()));
             }
             $date = DateTime::createFromFormat('U', $value);
             $date->setTime(0, 0, 0);
             $query->setMax($date->format('U'));
             $rangeQueries[$key] = $query;
         } else {
             throw new \InvalidArgumentException(sprintf('Either the given restriction is of an invalid type, or the restriction type "%s" has not been implemented.', get_class($restriction)));
         }
     }
     if (count($rangeQueries) == 0) {
         if ($countOnly) {
             $tmpKey = 'redis-orm:cache:' . md5(time() . $criteria->__toString());
             array_unshift($keys, $tmpKey);
             call_user_func_array(array($this->redis, 'sinterstore'), $keys);
             $this->redis->expire($tmpKey, 1200);
             return $this->redis->scard($tmpKey);
         }
         return call_user_func_array(array($this->redis, 'sinter'), $keys);
     }
     $tmpKey = 'redis-orm:cache:' . md5(time() . $criteria->__toString());
     $rangeKeys = $this->handleRangeQueries($rangeQueries, $tmpKey);
     //$keys = array_merge($keys, array_keys($rangeQueries));
     $keys = array_merge($keys, $rangeKeys);
     array_unshift($keys, $tmpKey, count($keys));
     array_push($keys, 'AGGREGATE', 'MAX');
     call_user_func_array(array($this->redis, 'zinterstore'), $keys);
     //$this->handleRangeQueries($rangeQueries, $tmpKey);
     $this->redis->expire($tmpKey, 1200);
     if ($countOnly) {
         return $this->redis->zcard($tmpKey);
     }
     return $this->redis->zrange($tmpKey, 0, -1);
 }
開發者ID:justintaft01,項目名稱:redis-orm,代碼行數:76,代碼來源:ObjectRepository.php

示例4: existsZSet

 /**
  * 有序集合是否存在
  * @param $key
  * @return bool
  */
 public function existsZSet($key)
 {
     return $this->redis->zcard($key) > 0;
 }
開發者ID:inhere,項目名稱:php-librarys,代碼行數:9,代碼來源:Redis.php


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