Spring模版接口 ZSetOperations的 Long count(K key, double min, double max)方法
count方法
@Nullable
Long count(K key, double min, double max)
计算排序集 中 分数介于最小值和最大值之间的元素数量。
Count number of elements within sorted set with scores between min and max.
Parameters:
- key - must not be null.
- min -
- max -
Returns: null when used in pipeline / transaction.
See Also: Redis Documentation: ZCOUNT https://redis.io/docs/latest/commands/zcount/
Redis中的ZCOUNT
返回键对应的有序集合中,分数介于 min 和 max 之间的元素数量。
Returns the number of elements in the sorted set at key with a score between min and max.
min 和 max 参数的语义与 ZRANGEBYSCORE 中的描述相同。
The min and max arguments have the same semantic as described for ZRANGEBYSCORE.
注意:该命令的复杂度仅为 O(log(N)),因为它使用元素 排序(参见 ZRANK)来了解范围。因此,无需进行与范围大小成比例的工作。
Note: the command has a complexity of just O(log(N)) because it uses elements ranks (see ZRANK) to get an idea of the range. Because of this there is no need to do a work proportional to the size of the range.
代码实例
long count_oneminute = stringRedisTemplate.opsForZSet().count(SENDCODE_SENDTIME_KEY + phone, oneMinuteAgo, System.currentTimeMillis());
统计在键为SENDCODE_SENDTIME_KEY + phone的有序集合中,分数(score)在oneMinuteAgo到当前时间之间的元素数量。

浙公网安备 33010602011771号