ZRANGEBYSCORE

AttentionThis page documents an earlier version. Go to the latest (v2.1)version.

Synopsis

ZRANGEBYSCORE key min max [WITHSCORES]This command fetches members for which score is in the given min max range. min and max are doubles.If key does not exist, an empty range is returned. If key corresponds to a nonsorted-set, an error is raised. Special bounds -inf and +inf are also supported to retrieve an entire range.min and max are inclusive unless they are prefixed with (, in which case they areexclusive.

Return Value

Returns a list of members found in the range specified by min, max, unless the WITHSCORES option is specified (see below).

ZRANGEBYSCORE Options

  • WITHSCORES: Makes the command return both the member and its score.

Examples

You can do this as shown below.

  1. $ ZADD z_key 1.0 v1 2.0 v2
  1. (integer) 2

Retrieve all members.

  1. $ ZRANGEBYSCORE z_key -inf +inf
  1. 1) "v1"
  2. 2) "v2"

Retrieve all member score pairs.

  1. $ ZRANGEBYSCORE z_key -inf +inf WITHSCORES
  1. 1) "v1"
  2. 2) "1.0"
  3. 3) "v2"
  4. 4) "2.0"

Bounds are inclusive.

  1. $ ZRANGEBYSCORE z_key 1.0 2.0
  1. 1) "v1"
  2. 2) "v2"

Bounds are exclusive.

  1. $ ZRANGEBYSCORE z_key (1.0 (2.0
  1. (empty list or set)

See Also

zadd, zcard, zrange, zrem, zrevrange