2 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN">
5 <link type=
"text/css" rel=
"stylesheet" href=
"style.css" />
12 <img style=
"border:none" alt=
"Redis Documentation" src=
"redis.png">
16 <div id=
"pagecontent">
18 <!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
19 <b>ZrangebyscoreCommand: Contents
</b><br> <a href=
"#ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` (Redis >">ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` (Redis
></a><br> <a href=
"#ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` `[`WITHSCORES`]` (Redis >">ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` `[`WITHSCORES`]` (Redis
></a><br> <a href=
"#ZCOUNT _key_ _min_ _max_">ZCOUNT _key_ _min_ _max_
</a><br> <a href=
"#Exclusive intervals and infinity">Exclusive intervals and infinity
</a><br> <a href=
"#Return value">Return value
</a><br> <a href=
"#Examples">Examples
</a>
22 <h1 class=
"wikiname">ZrangebyscoreCommand
</h1>
29 #sidebar
<a href=
"SortedSetCommandsSidebar.html">SortedSetCommandsSidebar
</a><h1><a name=
"ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` (Redis >">ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` (Redis
></a></h1> 1.1) =
30 <h1><a name=
"ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` `[`WITHSCORES`]` (Redis >">ZRANGEBYSCORE _key_ _min_ _max_ `[`LIMIT _offset_ _count_`]` `[`WITHSCORES`]` (Redis
></a></h1> 1.3.4) =
31 <h1><a name=
"ZCOUNT _key_ _min_ _max_">ZCOUNT _key_ _min_ _max_
</a></h1>
32 <i>Time complexity: O(log(N))+O(M) with N being the number of elements in the sorted set and M the number of elements returned by the command, so if M is constant (for instance you always ask for the first ten elements with LIMIT) you can consider it O(log(N))
</i><blockquote>Return the all the elements in the sorted set at key with a score between_min_ and
<i>max
</i> (including elements with score equal to min or max).
</blockquote>
33 <blockquote>The elements having the same score are returned sorted lexicographically asASCII strings (this follows from a property of Redis sorted sets and does notinvolve further computation).
</blockquote>
34 <blockquote>Using the optional LIMIT it's possible to get only a range of the matchingelements in an SQL-alike way. Note that if
<i>offset
</i> is large the commandsneeds to traverse the list for
<i>offset
</i> elements and this adds up to theO(M) figure.
</blockquote>
35 <blockquote>The
<b>ZCOUNT
</b> command is similar to
<b>ZRANGEBYSCORE
</b> but instead of returningthe actual elements in the specified interval, it just returns the numberof matching elements.
</blockquote><h2><a name=
"Exclusive intervals and infinity">Exclusive intervals and infinity
</a></h2>
36 <i>min
</i> and
<i>max
</i> can be -inf and +inf, so that you are not required to know what's the greatest or smallest element in order to take, for instance, elements
"up to a given value
".
<br/><br/>Also while the interval is for default closed (inclusive) it's possible to specify open intervals prefixing the score with a
"(
" character, so for instance:
37 <pre class=
"codeblock python" name=
"code">
38 ZRANGEBYSCORE zset (
1.3 5
40 Will return all the values with score
<b>> 1.3 and
<=
5</b>, while for instance:
41 <pre class=
"codeblock python python" name=
"code">
42 ZRANGEBYSCORE zset (
5 (
10
44 Will return all the values with score
<b>> 5 and
< 10</b> (
5 and
10 excluded).
45 <h2><a name=
"Return value">Return value
</a></h2>ZRANGEBYSCORE returns a
<a href=
"ReplyTypes.html">Multi bulk reply
</a> specifically a list of elements in the specified score range.
<br/><br/>ZCOUNT returns a
<a href=
"ReplyTypes.html">Integer reply
</a> specifically the number of elements matching the specified score range.
46 <h2><a name=
"Examples">Examples
</a></h2>
47 <pre class=
"codeblock python python python" name=
"code">
48 redis
> zadd zset
1 foo
50 redis
> zadd zset
2 bar
52 redis
> zadd zset
3 biz
54 redis
> zadd zset
4 foz
56 redis
> zrangebyscore zset -inf +inf
61 redis
> zcount zset
1 2
63 redis
> zrangebyscore zset
1 2
66 redis
> zrangebyscore zset (
1 2
68 redis
> zrangebyscore zset (
1 (
2