{
  "schema_version": 2,
  "id": "commands/zrange",
  "title": "ZRANGE",
  "url": "https://redis.io/docs/latest/commands/zrange/",
  "summary": "Returns members in a sorted set within a range of indexes.",
  "since": "1.2.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:43+01:00",
  "page_type": "content",
  "content_hash": "ac760cb04569f58e4a7119f1fcc1507cbe666f3de425d306ab2f278121a8ec6a",
  "sections": [
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key that holds the sorted set.\n\n</details>\n\n<details open><summary><code>start</code></summary>\n\nThe start of the range. By default a zero-based index (negatives count from the end); a score bound with `BYSCORE`; or a lexicographical bound with `BYLEX`.\n\n</details>\n\n<details open><summary><code>stop</code></summary>\n\nThe end of the range, inclusive. Interpreted the same way as `start`.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>BYSCORE | BYLEX</code></summary>\n\nInterpret the range as a score range (`BYSCORE`) or a lexicographical range (`BYLEX`) instead of an index range.\n\n</details>\n\n<details open><summary><code>REV</code></summary>\n\nReverse the ordering so results are returned from high to low.\n\n</details>\n\n<details open><summary><code>LIMIT offset count</code></summary>\n\nSkip `offset` matching members and return up to `count` of them. Requires `BYSCORE` or `BYLEX`. A negative `count` returns all remaining members.\n\n</details>\n\n<details open><summary><code>WITHSCORES</code></summary>\n\nAlso return the score of each member.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Foundational: Retrieve a range of members from a sorted set by index using ZRANGE (supports negative indexes, inclusive range)\n\n**Difficulty:** Beginner\n\n**Commands:** ZADD, ZRANGE\n\n**Complexity:**\n- ZADD: O(log(N)\n- ZRANGE: O(log(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nThe following example using `WITHSCORES` shows how the command returns always an array, but this time, populated with *element_1*, *score_1*, *element_2*, *score_2*, ..., *element_N*, *score_N*.\n\nReturn scores with members: Retrieve members with their scores from a sorted set using ZRANGE with WITHSCORES option\n\n**Difficulty:** Intermediate\n\n**Commands:** DEL, ZADD, ZRANGE\n\n**Complexity:**\n- DEL: O(N)\n- ZADD: O(log(N)\n- ZRANGE: O(log(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nThis example shows how to query the sorted set by score, excluding the value `1` and up to infinity, returning only the second element of the result:\n\nQuery by score: Query a sorted set by score range using ZRANGE with BYSCORE and LIMIT options (supports exclusive ranges and pagination)\n\n**Difficulty:** Intermediate\n\n**Commands:** DEL, ZADD, ZRANGE\n\n**Complexity:**\n- DEL: O(N)\n- ZADD: O(log(N)\n- ZRANGE: O(log(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]"
    },
    {
      "id": "details",
      "title": "Details",
      "role": "content",
      "text": ""
    },
    {
      "id": "common-behavior-and-options",
      "title": "Common behavior and options",
      "role": "content",
      "text": "The order of elements is from the lowest to the highest score. Elements with the same score are ordered lexicographically.\n\nThe optional `REV` argument reverses the ordering, so elements are ordered from highest to lowest score, and score ties are resolved by reverse lexicographical ordering.\n\nThe optional `LIMIT` argument can be used to obtain a sub-range from the matching elements (similar to _SELECT LIMIT offset, count_ in SQL).\nA negative `<count>` returns all elements from the `<offset>`. Keep in mind that if `<offset>` is large, the sorted set needs to be traversed for `<offset>` elements before getting to the elements to return, which can add up to O(N) time complexity.\n\nThe optional `WITHSCORES` argument supplements the command's reply with the scores of elements returned. The returned list contains `value1,score1,...,valueN,scoreN` instead of `value1,...,valueN`. Client libraries are free to return a more appropriate data type (suggestion: an array with (value, score) arrays/tuples)."
    },
    {
      "id": "index-ranges",
      "title": "Index ranges",
      "role": "content",
      "text": "By default, the command performs an index range query. The `<start>` and `<stop>` arguments represent zero-based indexes, where `0` is the first element, `1` is the next element, and so on. These arguments specify an **inclusive range**, so for example, `ZRANGE myzset 0 1` will return both the first and the second element of the sorted set.\n\nThe indexes can also be negative numbers indicating offsets from the end of the sorted set, with `-1` being the last element of the sorted set, `-2` the penultimate element, and so on.\n\nOut of range indexes do not produce an error.\n\nIf `<start>` is greater than either the end index of the sorted set or `<stop>`, an empty list is returned.\n\nIf `<stop>` is greater than the end index of the sorted set, Redis will use the last element of the sorted set."
    },
    {
      "id": "score-ranges",
      "title": "Score ranges",
      "role": "content",
      "text": "When the `BYSCORE` option is provided, the command behaves like [`ZRANGEBYSCORE`](https://redis.io/docs/latest/commands/zrangebyscore) and returns the range of elements from the sorted set having scores equal or between `<start>` and `<stop>`.\n\n`<start>` and `<stop>` can be `-inf` and `+inf`, denoting the negative and positive infinities, respectively. This means that you are not required to know the highest or lowest score in the sorted set to get all elements from or up to a certain score.\n\nBy default, the score intervals specified by `<start>` and `<stop>` are closed (inclusive).\nIt is possible to specify an open interval (exclusive) by prefixing the score\nwith the character `(`.\n\nFor example:\n\n[code example]\n\nWill return all elements with `1 < score <= 5` while:\n\n[code example]\n\nWill return all the elements with `5 < score < 10` (5 and 10 excluded)."
    },
    {
      "id": "reverse-ranges",
      "title": "Reverse ranges",
      "role": "content",
      "text": "Using the `REV` option reverses the sorted set, with index 0 as the element with the highest score.\n\nBy default, `<start>` must be less than or equal to `<stop>` to return anything.\nHowever, if the `BYSCORE`, or `BYLEX` options are selected, the `<start>` is the highest score to consider, and `<stop>` is the lowest score to consider, therefore `<start>` must be greater than or equal to `<stop>` in order to return anything.\n\nFor example:\n\n[code example]\n\nWill return the elements between index 5 and 10 in the reversed index.\n\n[code example]\n\nWill return all elements with scores less than 10 and greater than 5."
    },
    {
      "id": "lexicographical-ranges",
      "title": "Lexicographical ranges",
      "role": "content",
      "text": "When the `BYLEX` option is used, the command behaves like [`ZRANGEBYLEX`](https://redis.io/docs/latest/commands/zrangebylex) and returns the range of elements from the sorted set between the `<start>` and `<stop>` lexicographical closed range intervals.\n\nNote that lexicographical ordering relies on all elements having the same score. The reply is unspecified when the elements have different scores.\n\nValid `<start>` and `<stop>` must start with `(` or `[`, in order to specify\nwhether the range interval is exclusive or inclusive, respectively.\n\nThe special values of `+` or `-` for `<start>` and `<stop>` mean positive and negative infinite strings, respectively, so for instance the command `ZRANGE myzset - + BYLEX` is guaranteed to return all the elements in the sorted set, providing that all the elements have the same score.\n\nThe `REV` options reverses the order of the `<start>` and `<stop>` elements, where `<start>` must be lexicographically greater than `<stop>` to produce a non-empty result.\n\n#### Lexicographical comparison of strings\n\nStrings are compared as a binary array of bytes. Because of how the ASCII character set is specified, this means that usually this also have the effect of comparing normal ASCII characters in an obvious dictionary way. However, this is not true if non-plain ASCII strings are used (for example, utf8 strings).\n\nHowever, the user can apply a transformation to the encoded string so that the first part of the element inserted in the sorted set will compare as the user requires for the specific application. For example, if I want to\nadd strings that will be compared in a case-insensitive way, but I still\nwant to retrieve the real case when querying, I can add strings in the\nfollowing way:\n\n    ZADD autocomplete 0 foo:Foo 0 bar:BAR 0 zap:zap\n\nBecause of the first *normalized* part in every element (before the colon character), we are forcing a given comparison. However, after the range is queried using `ZRANGE ... BYLEX`, the application can display to the user the second part of the string, after the colon.\n\nThe binary nature of the comparison allows to use sorted sets as a general purpose index, for example, the first part of the element can be a 64-bit big-endian number. Since big-endian numbers have the most significant bytes in the initial positions, the binary comparison will match the numerical comparison of the numbers. This can be used in order to implement range queries on 64-bit values. As in the example below, after the first 8 bytes, we can store the value of the element we are indexing."
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> | <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): a list of members in the specified range with, optionally, their scores when the _WITHSCORES_ option is given.\n\n**RESP3:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): a list of members in the specified range with, optionally, their scores when the _WITHSCORES_ option is given."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> ZADD myzset 1 \"one\" 2 \"two\" 3 \"three\"\n(integer) 3\n> ZRANGE myzset 0 -1\n1) \"one\"\n2) \"two\"\n3) \"three\"\n> ZRANGE myzset 2 3\n1) \"three\"\n> ZRANGE myzset -2 -1\n1) \"two\"\n2) \"three\"",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "csharp",
      "code": "long zRangeResult1 = db.SortedSetAdd(\n            \"myzset\",\n            [\n                new(\"one\", 1),\n                new(\"two\", 2),\n                new(\"three\", 3)\n            ]\n        );\n        Console.WriteLine(zRangeResult1);   // >>> 3\n\n        RedisValue[] zRangeResult2 = db.SortedSetRangeByRank(\"myzset\", 0, -1);\n        Console.WriteLine(string.Join(\", \", zRangeResult2));\n        // >>> one, two, three\n\n        RedisValue[] zRangeResult3 = db.SortedSetRangeByRank(\"myzset\", 2, 3);\n        Console.WriteLine(string.Join(\", \", zRangeResult3));\n        // >>> three\n\n        RedisValue[] zRangeResult4 = db.SortedSetRangeByRank(\"myzset\", -2, -1);\n        Console.WriteLine(string.Join(\", \", zRangeResult4));\n        // >>> two, three",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "go",
      "code": "zrangeResult1, err := rdb.ZAdd(ctx, \"myzset\",\n\t\tredis.Z{Member: \"one\", Score: 1},\n\t\tredis.Z{Member: \"two\", Score: 2},\n\t\tredis.Z{Member: \"three\", Score: 3},\n\t).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(zrangeResult1) // >>> 3\n\n\tzrangeResult2, err := rdb.ZRange(ctx, \"myzset\", 0, -1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(zrangeResult2) // >>> [one two three]\n\n\tzrangeResult3, err := rdb.ZRange(ctx, \"myzset\", 2, 3).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(zrangeResult3) // >>> [three]\n\n\tzrangeResult4, err := rdb.ZRange(ctx, \"myzset\", -2, -1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(zrangeResult4) // >>> [two three]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "java",
      "code": "CompletableFuture<Void> zRange1Example = asyncCommands.zadd(\"myzset\",\n                    ScoredValue.just(1d, \"one\"), ScoredValue.just(2d, \"two\"), ScoredValue.just(3d, \"three\"))\n                    .thenCompose(res5 -> {\n                        System.out.println(res5); // >>> 3\n                        return asyncCommands.zrange(\"myzset\", 0, -1);\n                    }).thenCompose(res6 -> {\n                        System.out.println(res6); // >>> [one, two, three]\n                        return asyncCommands.zrange(\"myzset\", 2, 3);\n                    }).thenCompose(res7 -> {\n                        System.out.println(res7); // >>> [three]\n                        return asyncCommands.zrange(\"myzset\", -2, -1);\n                    }).thenAccept(res8 -> {\n                        System.out.println(res8); // >>> [two, three]\n                    }).toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "Mono<Void> zRange1Example = reactiveCommands.zadd(\"myzset\",\n                    ScoredValue.just(1d, \"one\"), ScoredValue.just(2d, \"two\"), ScoredValue.just(3d, \"three\"))\n                    .doOnNext(res5 -> {\n                        System.out.println(res5); // >>> 3\n                    })\n                    .then(reactiveCommands.zrange(\"myzset\", 0, -1).collectList())\n                    .doOnNext(res6 -> {\n                        System.out.println(res6); // >>> [one, two, three]\n                    })\n                    .then(reactiveCommands.zrange(\"myzset\", 2, 3).collectList())\n                    .doOnNext(res7 -> {\n                        System.out.println(res7); // >>> [three]\n                    })\n                    .then(reactiveCommands.zrange(\"myzset\", -2, -1).collectList())\n                    .doOnNext(res8 -> {\n                        System.out.println(res8); // >>> [two, three]\n                    })\n                    .then();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "Map<String, Double> zRangeExampleParams1 = new HashMap<>();\n        zRangeExampleParams1.put(\"one\", 1.0);\n        zRangeExampleParams1.put(\"two\", 2.0);\n        zRangeExampleParams1.put(\"three\", 3.0);\n        long zRangeResult1 = jedis.zadd(\"myzset\", zRangeExampleParams1);\n        System.out.println(zRangeResult1);  // >>> 3\n\n        List<String> zRangeResult2 = jedis.zrange(\"myzset\", new ZRangeParams(0, -1));\n        System.out.println(String.join(\", \", zRangeResult2));   // >>> one, two, three\n\n        List<String> zRangeResult3 = jedis.zrange(\"myzset\", new ZRangeParams(2, 3));\n        System.out.println(String.join(\", \", zRangeResult3));   // >> three\n\n        List<String> zRangeResult4 = jedis.zrange(\"myzset\", new ZRangeParams(-2, -1));\n        System.out.println(String.join(\", \", zRangeResult4));   // >> two, three",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "javascript",
      "code": "const val5 = await client.zAdd(\"myzset\", [\n  { value: 'one', score: 1 },\n  { value: 'two', score: 2 },\n  { value: 'three', score: 3 }\n]);\nconsole.log(val5);\n// returns 3\n\nconst val6 = await client.zRange('myzset', 0, -1);\nconsole.log(val6);\n// returns ['one', 'two', 'three']\n\nconst val7 = await client.zRange('myzset', 2, 3);\nconsole.log(val7);\n// returns ['three']\n\nconst val8 = await client.zRange('myzset', -2, -1);\nconsole.log(val8);\n// returns ['two', 'three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "javascript",
      "code": "const res5 = await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');\nconsole.log(res5); // >>> 3\n\nconst res6 = await redis.zrange('myzset', 0, -1);\nconsole.log(res6); // >>> ['one', 'two', 'three']\n\nconst res7 = await redis.zrange('myzset', 2, 3);\nconsole.log(res7); // >>> ['three']\n\nconst res8 = await redis.zrange('myzset', -2, -1);\nconsole.log(res8); // >>> ['two', 'three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "javascript",
      "code": "const val5 = await client.zAdd(\"myzset\", [\n  { value: 'one', score: 1 },\n  { value: 'two', score: 2 },\n  { value: 'three', score: 3 }\n]);\nconsole.log(val5);\n// returns 3\n\nconst val6 = await client.zRange('myzset', 0, -1);\nconsole.log(val6);\n// returns ['one', 'two', 'three']\n\nconst val7 = await client.zRange('myzset', 2, 3);\nconsole.log(val7);\n// returns ['three']\n\nconst val8 = await client.zRange('myzset', -2, -1);\nconsole.log(val8);\n// returns ['two', 'three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "javascript",
      "code": "const res5 = await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');\nconsole.log(res5); // >>> 3\n\nconst res6 = await redis.zrange('myzset', 0, -1);\nconsole.log(res6); // >>> ['one', 'two', 'three']\n\nconst res7 = await redis.zrange('myzset', 2, 3);\nconsole.log(res7); // >>> ['three']\n\nconst res8 = await redis.zrange('myzset', -2, -1);\nconsole.log(res8); // >>> ['two', 'three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "php",
      "code": "$res5 = $r->zadd('myzset', ['one' => 1, 'two' => 2, 'three' => 3]);\n        echo $res5 . PHP_EOL; // >>> 3\n\n        $res6 = $r->zrange('myzset', 0, -1);\n        echo json_encode($res6) . PHP_EOL; // >>> [\"one\",\"two\",\"three\"]\n\n        $res7 = $r->zrange('myzset', 2, 3);\n        echo json_encode($res7) . PHP_EOL; // >>> [\"three\"]\n\n        $res8 = $r->zrange('myzset', -2, -1);\n        echo json_encode($res8) . PHP_EOL; // >>> [\"two\",\"three\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "python",
      "code": "res = r.zadd(\"myzset\", {\"one\": 1, \"two\":2, \"three\":3})\nprint(res)\n# >>> 3\n\nres = r.zrange(\"myzset\", 0, -1)\nprint(res)\n# >>> ['one', 'two', 'three']\n\nres = r.zrange(\"myzset\", 2, 3)\nprint(res)\n# >>> ['three']\n\nres = r.zrange(\"myzset\", -2, -1)\nprint(res)\n# >>> ['two', 'three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex12",
      "language": "ruby",
      "code": "res5 = r.zadd('myzset', [[1, 'one'], [2, 'two'], [3, 'three']])\nputs res5 # >>> 3\n\nres6 = r.zrange('myzset', 0, -1)\nputs res6.inspect # >>> [\"one\", \"two\", \"three\"]\n\nres7 = r.zrange('myzset', 2, 3)\nputs res7.inspect # >>> [\"three\"]\n\nres8 = r.zrange('myzset', -2, -1)\nputs res8.inspect # >>> [\"two\", \"three\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex13",
      "language": "rust",
      "code": "if let Ok(res5) = r.zadd_multiple(\"myzset\", &[(1, \"one\"), (2, \"two\"), (3, \"three\")]).await {\n            let res5: i32 = res5;\n            println!(\"{res5}\"); // >>> 3\n        }\n\n        if let Ok(res6) = r.zrange(\"myzset\", 0, -1).await {\n            let res6: Vec<String> = res6;\n            println!(\"{res6:?}\"); // >>> [\"one\", \"two\", \"three\"]\n        }\n\n        if let Ok(res7) = r.zrange(\"myzset\", 2, 3).await {\n            let res7: Vec<String> = res7;\n            println!(\"{res7:?}\"); // >>> [\"three\"]\n        }\n\n        if let Ok(res8) = r.zrange(\"myzset\", -2, -1).await {\n            let res8: Vec<String> = res8;\n            println!(\"{res8:?}\"); // >>> [\"two\", \"three\"]\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex14",
      "language": "rust",
      "code": "if let Ok(res5) = r.zadd_multiple(\"myzset\", &[(1, \"one\"), (2, \"two\"), (3, \"three\")]) {\n            let res5: i32 = res5;\n            println!(\"{res5}\"); // >>> 3\n        }\n\n        if let Ok(res6) = r.zrange(\"myzset\", 0, -1) {\n            let res6: Vec<String> = res6;\n            println!(\"{res6:?}\"); // >>> [\"one\", \"two\", \"three\"]\n        }\n\n        if let Ok(res7) = r.zrange(\"myzset\", 2, 3) {\n            let res7: Vec<String> = res7;\n            println!(\"{res7:?}\"); // >>> [\"three\"]\n        }\n\n        if let Ok(res8) = r.zrange(\"myzset\", -2, -1) {\n            let res8: Vec<String> = res8;\n            println!(\"{res8:?}\"); // >>> [\"two\", \"three\"]\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex15",
      "language": "plaintext",
      "code": "> DEL myzset\n(integer) 1\n> ZADD myzset 1 \"one\" 2 \"two\" 3 \"three\"\n(integer) 3\n> ZRANGE myzset 0 1 WITHSCORES\n1) \"one\"\n2) \"1\"\n3) \"two\"\n4) \"2\"",
      "section_id": "examples"
    },
    {
      "id": "examples-ex16",
      "language": "csharp",
      "code": "long zRangeResult5 = db.SortedSetAdd(\n            \"myzset\",\n            [\n                new(\"one\", 1),\n                new(\"two\", 2),\n                new(\"three\", 3)\n            ]\n        );\n\n        SortedSetEntry[] zRangeResult6 = db.SortedSetRangeByRankWithScores(\"myzset\", 0, 1);\n        Console.WriteLine($\"{string.Join(\", \", zRangeResult6.Select(b => $\"{b.Element}: {b.Score}\"))}\");\n        // >>> one: 1, two: 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex17",
      "language": "go",
      "code": "zRangeResult5, err := rdb.ZAdd(ctx, \"myzset\",\n\t\tredis.Z{Member: \"one\", Score: 1},\n\t\tredis.Z{Member: \"two\", Score: 2},\n\t\tredis.Z{Member: \"three\", Score: 3},\n\t).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(zRangeResult5) // >>> 3\n\n\tzRangeResult6, err := rdb.ZRangeWithScores(ctx, \"myzset\", 0, 1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(zRangeResult6) // >>> [{1 one} {2 two}]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex18",
      "language": "java",
      "code": "CompletableFuture<Void> zRange2Example = asyncCommands.zadd(\"myzset\",\n                    ScoredValue.just(1d, \"one\"), ScoredValue.just(2d, \"two\"), ScoredValue.just(3d, \"three\"))\n                    .thenCompose(res9 -> {\n                        return asyncCommands.zrangeWithScores(\"myzset\", 0, 1);\n                    }).thenAccept(res10 -> {\n                        System.out.println(res10);\n                        // >>> [ScoredValue[1.000000, one], ScoredValue[2.000000, two]]\n                    }).toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex19",
      "language": "java",
      "code": "Mono<Void> zRange2Example = reactiveCommands.zadd(\"myzset\",\n                    ScoredValue.just(1d, \"one\"), ScoredValue.just(2d, \"two\"), ScoredValue.just(3d, \"three\"))\n                    .then(reactiveCommands.zrangeWithScores(\"myzset\", 0, 1).collectList())\n                    .doOnNext(res9 -> {\n                        System.out.println(res9);\n                        // >>> [ScoredValue[1.000000, one], ScoredValue[2.000000, two]]\n                    })\n                    .then();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex20",
      "language": "java",
      "code": "Map<String, Double> zRangeExampleParams2 = new HashMap<>();\n        zRangeExampleParams2.put(\"one\", 1.0);\n        zRangeExampleParams2.put(\"two\", 2.0);\n        zRangeExampleParams2.put(\"three\", 3.0);\n        long zRangeResult5 = jedis.zadd(\"myzset\", zRangeExampleParams2);\n        System.out.println(zRangeResult5);  // >>> 3\n\n        List<Tuple> zRangeResult6 = jedis.zrangeWithScores(\"myzset\", new ZRangeParams(0, 1));\n\n        for (Tuple item: zRangeResult6) {\n            System.out.println(\"Element: \" + item.getElement() + \", Score: \" + item.getScore());\n        }\n        // >>> Element: one, Score: 1.0\n        // >>> Element: two, Score: 2.0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex21",
      "language": "javascript",
      "code": "const val9 = await client.zAdd(\"myzset\", [\n  { value: 'one', score: 1 },\n  { value: 'two', score: 2 },\n  { value: 'three', score: 3 }\n]);\nconsole.log(val9);\n// returns 3\n\nconst val10 = await client.zRangeWithScores('myzset', 0, 1);\nconsole.log(val10);\n// returns [{value: 'one', score: 1}, {value: 'two', score: 2}]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex22",
      "language": "javascript",
      "code": "await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');\n\nconst res9 = await redis.zrange('myzset', 0, 1, 'WITHSCORES');\nconsole.log(res9); // >>> ['one', '1', 'two', '2']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex23",
      "language": "javascript",
      "code": "const val9 = await client.zAdd(\"myzset\", [\n  { value: 'one', score: 1 },\n  { value: 'two', score: 2 },\n  { value: 'three', score: 3 }\n]);\nconsole.log(val9);\n// returns 3\n\nconst val10 = await client.zRangeWithScores('myzset', 0, 1);\nconsole.log(val10);\n// returns [{value: 'one', score: 1}, {value: 'two', score: 2}]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex24",
      "language": "javascript",
      "code": "await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');\n\nconst res9 = await redis.zrange('myzset', 0, 1, 'WITHSCORES');\nconsole.log(res9); // >>> ['one', '1', 'two', '2']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex25",
      "language": "php",
      "code": "$r->zadd('myzset', ['one' => 1, 'two' => 2, 'three' => 3]);\n\n        $res9 = $r->zrange('myzset', 0, 1, ['withscores' => true]);\n        echo json_encode($res9) . PHP_EOL; // >>> {\"one\":\"1\",\"two\":\"2\"}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex26",
      "language": "python",
      "code": "res = r.zadd(\"myzset\", {\"one\": 1, \"two\":2, \"three\":3})\nres = r.zrange(\"myzset\", 0, 1, withscores=True)\nprint(res)\n# >>> [('one', 1.0), ('two', 2.0)]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex27",
      "language": "ruby",
      "code": "r.zadd('myzset', [[1, 'one'], [2, 'two'], [3, 'three']])\n\nres9 = r.zrange('myzset', 0, 1, with_scores: true)\nputs res9.inspect # >>> [[\"one\", 1.0], [\"two\", 2.0]]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex28",
      "language": "rust",
      "code": "let _: Result<i32, _> = r.zadd_multiple(\"myzset\", &[(1, \"one\"), (2, \"two\"), (3, \"three\")]).await;\n\n        if let Ok(res9) = r.zrange_withscores(\"myzset\", 0, 1).await {\n            let res9: Vec<(String, f64)> = res9;\n            println!(\"{res9:?}\"); // >>> [(\"one\", 1.0), (\"two\", 2.0)]\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex29",
      "language": "rust",
      "code": "let _: Result<i32, _> = r.zadd_multiple(\"myzset\", &[(1, \"one\"), (2, \"two\"), (3, \"three\")]);\n\n        if let Ok(res9) = r.zrange_withscores(\"myzset\", 0, 1) {\n            let res9: Vec<(String, f64)> = res9;\n            println!(\"{res9:?}\"); // >>> [(\"one\", 1.0), (\"two\", 2.0)]\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex30",
      "language": "plaintext",
      "code": "> DEL myzset\n(integer) 1\n> ZADD myzset 1 \"one\" 2 \"two\" 3 \"three\"\n(integer) 3\n> ZRANGE myzset (1 +inf BYSCORE LIMIT 1 1\n1) \"three\"",
      "section_id": "examples"
    },
    {
      "id": "examples-ex31",
      "language": "csharp",
      "code": "long zRangeResult7 = db.SortedSetAdd(\n            \"myzset\",\n            [\n                new(\"one\", 1),\n                new(\"two\", 2),\n                new(\"three\", 3)\n            ]\n        );\n\n        RedisValue[] zRangeResult8 = db.SortedSetRangeByScore(\n            \"myzset\",\n            1,\n            double.PositiveInfinity,\n            Exclude.Start,\n            skip: 1, take: 1\n        );\n        Console.WriteLine(string.Join(\", \", zRangeResult8));\n        // >>> three",
      "section_id": "examples"
    },
    {
      "id": "examples-ex32",
      "language": "go",
      "code": "zRangeResult7, err := rdb.ZAdd(ctx, \"myzset\",\n\t\tredis.Z{Member: \"one\", Score: 1},\n\t\tredis.Z{Member: \"two\", Score: 2},\n\t\tredis.Z{Member: \"three\", Score: 3},\n\t).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(zRangeResult7) // >>> 3\n\n\tzRangeResult8, err := rdb.ZRangeArgs(ctx,\n\t\tredis.ZRangeArgs{\n\t\t\tKey:     \"myzset\",\n\t\t\tByScore: true,\n\t\t\tStart:   \"(1\",\n\t\t\tStop:    \"+inf\",\n\t\t\tOffset:  1,\n\t\t\tCount:   1,\n\t\t},\n\t).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(zRangeResult8) // >>> [three]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex33",
      "language": "java",
      "code": "CompletableFuture<Void> zRange3Example = asyncCommands.zadd(\"myzset\",\n                    ScoredValue.just(1d, \"one\"), ScoredValue.just(2d, \"two\"), ScoredValue.just(3d, \"three\"))\n                    .thenCompose(res11 -> {\n                        return asyncCommands.zrangebyscore(\"myzset\",\n                                Range.from(Range.Boundary.excluding(1d), Range.Boundary.unbounded()),\n                                Limit.create(1, 1));\n                    }).thenAccept(res12 -> {\n                        System.out.println(res12); // >>> [three]\n                    }).toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex34",
      "language": "java",
      "code": "Mono<Void> zRange3Example = reactiveCommands.zadd(\"myzset\",\n                    ScoredValue.just(1d, \"one\"), ScoredValue.just(2d, \"two\"), ScoredValue.just(3d, \"three\"))\n                    .then(reactiveCommands.zrangebyscore(\"myzset\",\n                            Range.from(Range.Boundary.excluding(1d), Range.Boundary.unbounded()),\n                            Limit.create(1, 1)).collectList())\n                    .doOnNext(res10 -> {\n                        System.out.println(res10); // >>> [three]\n                    })\n                    .then();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex35",
      "language": "java",
      "code": "Map<String, Double> zRangeExampleParams3 = new HashMap<>();\n        zRangeExampleParams3.put(\"one\", 1.0);\n        zRangeExampleParams3.put(\"two\", 2.0);\n        zRangeExampleParams3.put(\"three\", 3.0);\n        long zRangeResult7 = jedis.zadd(\"myzset\", zRangeExampleParams3);\n        System.out.println(zRangeResult7);  // >>> 3\n\n        List<String> zRangeResult8 = jedis.zrangeByScore(\"myzset\", \"(1\", \"+inf\", 1, 1);\n        System.out.println(String.join(\", \", zRangeResult8));   // >>> three",
      "section_id": "examples"
    },
    {
      "id": "examples-ex36",
      "language": "javascript",
      "code": "const val11 = await client.zAdd(\"myzset\", [\n  { value: 'one', score: 1 },\n  { value: 'two', score: 2 },\n  { value: 'three', score: 3 }\n]);\nconsole.log(val11);\n// returns 3\n\nconst val12 = await client.zRange('myzset', 2, 3, { BY: 'SCORE', LIMIT: { offset: 1, count: 1 } });\nconsole.log(val12);\n// >>> ['three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex37",
      "language": "javascript",
      "code": "await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');\n\nconst res10 = await redis.zrange('myzset', '(1', '+inf', 'BYSCORE', 'LIMIT', 1, 1);\nconsole.log(res10); // >>> ['three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex38",
      "language": "javascript",
      "code": "const val11 = await client.zAdd(\"myzset\", [\n  { value: 'one', score: 1 },\n  { value: 'two', score: 2 },\n  { value: 'three', score: 3 }\n]);\nconsole.log(val11);\n// returns 3\n\nconst val12 = await client.zRange('myzset', 2, 3, { BY: 'SCORE', LIMIT: { offset: 1, count: 1 } });\nconsole.log(val12);\n// >>> ['three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex39",
      "language": "javascript",
      "code": "await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');\n\nconst res10 = await redis.zrange('myzset', '(1', '+inf', 'BYSCORE', 'LIMIT', 1, 1);\nconsole.log(res10); // >>> ['three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex40",
      "language": "php",
      "code": "$r->zadd('myzset', ['one' => 1, 'two' => 2, 'three' => 3]);\n\n        $res10 = $r->zrange('myzset', '(1', '+inf', ['byscore' => true, 'limit' => [1, 1]]);\n        echo json_encode($res10) . PHP_EOL; // >>> [\"three\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex41",
      "language": "python",
      "code": "res = r.zadd(\"myzset\", {\"one\": 1, \"two\":2, \"three\":3})\nres = r.zrange(\"myzset\", 2, 3, byscore=True, offset=1, num=1)\nprint(res)\n# >>> ['three']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex42",
      "language": "ruby",
      "code": "r.zadd('myzset', [[1, 'one'], [2, 'two'], [3, 'three']])\n\nres10 = r.zrange('myzset', '(1', '+inf', by_score: true, limit: [1, 1])\nputs res10.inspect # >>> [\"three\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex43",
      "language": "rust",
      "code": "let _: Result<i32, _> = r.zadd_multiple(\"myzset\", &[(1, \"one\"), (2, \"two\"), (3, \"three\")]).await;\n\n        if let Ok(res10) = r.zrangebyscore_limit(\"myzset\", \"(1\", \"+inf\", 1, 1).await {\n            let res10: Vec<String> = res10;\n            println!(\"{res10:?}\"); // >>> [\"three\"]\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex44",
      "language": "rust",
      "code": "let _: Result<i32, _> = r.zadd_multiple(\"myzset\", &[(1, \"one\"), (2, \"two\"), (3, \"three\")]);\n\n        if let Ok(res10) = r.zrangebyscore_limit(\"myzset\", \"(1\", \"+inf\", 1, 1) {\n            let res10: Vec<String> = res10;\n            println!(\"{res10:?}\"); // >>> [\"three\"]\n        }",
      "section_id": "examples"
    },
    {
      "id": "score-ranges-ex0",
      "language": "plaintext",
      "code": "ZRANGE zset (1 5 BYSCORE",
      "section_id": "score-ranges"
    },
    {
      "id": "score-ranges-ex1",
      "language": "plaintext",
      "code": "ZRANGE zset (5 (10 BYSCORE",
      "section_id": "score-ranges"
    },
    {
      "id": "reverse-ranges-ex0",
      "language": "plaintext",
      "code": "ZRANGE zset 5 10 REV",
      "section_id": "reverse-ranges"
    },
    {
      "id": "reverse-ranges-ex1",
      "language": "plaintext",
      "code": "ZRANGE zset 10 5 REV BYSCORE",
      "section_id": "reverse-ranges"
    }
  ]
}
