This article will introduce you to the usage of phpredis extension: zrangeByScore. I hope it will be helpful to friends in need~
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);
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])
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])
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]
phpredis zrangeByScore
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!