企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## zRangeByScore, zRevRangeByScore ##### *Description* Returns the elements of the sorted set stored at the specified key which have scores in the range \[start,end\]. Adding a parenthesis before `<span class="calibre12">start</span>` or `<span class="calibre12">end</span>` excludes it from the range. +inf and -inf are also valid limits. zRevRangeByScore returns the same items in reverse order, when the `<span class="calibre12">start</span>` and `<span class="calibre12">end</span>` parameters are swapped. 返回key对应的有序集合中score介于min和max之间的所有元素(包哈score等于min或者max的元素)。元素按照score从低到高的顺序排列。如果元素具有相同的score,那么会按照字典顺序排列。 可选的选项LIMIT可以用来获取一定范围内的匹配元素。如果偏移值较大,有序集合需要在获得将要返回的元素之前进行遍历,因此会增加O(N)的时间复杂度。可选的选项WITHSCORES可以使得在返回元素的同时返回元素的score,该选项自从Redis 2.0版本后可用。 ##### *Parameters* *key* *start*: string *end*: string *options*: array Two options are available: `<span class="calibre12">withscores => TRUE</span>`, and `<span class="calibre12">limit => array($offset, $count)</span>` ##### *Return value* *Array* containing the values in specified range. ##### *Example* ``` <pre class="calibre16">$redis->zAdd('key', 0, 'val0'); $redis->zAdd('key', 2, 'val2'); $redis->zAdd('key', 10, 'val10'); $redis->zRangeByScore('key', 0, 3); /* array('val0', 'val2') */ $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE); /* array('val0' => 0, 'val2' => 2) */ $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1)); /* array('val2' => 2) */ $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1)); /* array('val2') */ $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1)); /* array('val2' => 2) */ ```