当前位置: 首页>>代码示例>>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;未经允许,请勿转载。