Home > Backend Development > PHP Tutorial > Summarize the usage of zrangeByScore in phpredis

Summarize the usage of zrangeByScore in phpredis

藏色散人
Release: 2023-04-11 08:56:01
forward
7248 people have browsed it

This article will introduce you to the usage of phpredis extension: zrangeByScore. I hope it will be helpful to friends in need~

Summarize the usage of zrangeByScore in phpredis

phpredis zrangeByScore

Laravel currently recommends using the phpredis extension by default. Let’s summarize the usage of zrangeByscore:

$redis->zrangebyscore('key',$min,$max);// 查询通过scroe范围拿成员值,返回有序集key中,指定区间内的成员(分值升序:从小到大排)
// 分值降序使用:zrevrangebyscore('key',$min,$max);
Copy after login

1.$min,$max. These are commonly used parameters, but in special circumstances, I don’t know what $min and $max are. When the $max value is large, you need to use limits instead (inf, -inf, positive and negative infinite). [Recommended learning: PHP video tutorial]

2. To intercept the top 100, the fourth parameter is required:

$redis->zrangebyscore('key',$min,$max,['withscores'=>true , 'limit'=>['offset'=>0,'count'=>5])
Copy after login

The fourth parameter is an array, you need to pay attention to the limit Format, some reference is

$redis->zrangebyscore('key',$min,$max,['withscores'=>true , 'limit'=>[0,5])
Copy after login

but an error is reported during use. Check and track the phpredis source code in laravel and find that it is used in this way, so the correct parameter format is:

‘limit’=>[‘offset’=>0,’count’=>5]
Copy after login

phpredis zrangeByScore

Summarize the usage of zrangeByScore in phpredis

The above is the detailed content of Summarize the usage of zrangeByScore in phpredis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template