本文整理汇总了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;
}
示例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);
}
示例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);
}
示例4: existsZSet
/**
* 有序集合是否存在
* @param $key
* @return bool
*/
public function existsZSet($key)
{
return $this->redis->zcard($key) > 0;
}