{
  "schema_version": 2,
  "id": "commands/scan",
  "title": "SCAN",
  "url": "https://redis.io/docs/latest/commands/scan/",
  "summary": "Iterates over the key names in the database.",
  "since": "2.8.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:32+01:00",
  "page_type": "content",
  "content_hash": "6628d4e627cdd0485014e07bfe9521dacb672e93c97138160e6b92dfe22642ac",
  "sections": [
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>cursor</code></summary>\n\nThe cursor value. Start an iteration with `0`, then use the cursor returned by each call as the argument to the next call.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>MATCH pattern</code></summary>\n\nOnly return keys matching the given glob-style pattern.\n\n</details>\n\n<details open><summary><code>COUNT count</code></summary>\n\nA hint for the number of keys to return per iteration. The default is 10.\n\n</details>\n\n<details open><summary><code>TYPE type</code></summary>\n\nOnly return keys of the given type, such as `string`, `list`, or `set`.\n\n</details>"
    },
    {
      "id": "details",
      "title": "Details",
      "role": "content",
      "text": ""
    },
    {
      "id": "scan-basic-usage",
      "title": "SCAN basic usage",
      "role": "content",
      "text": "SCAN is a cursor based iterator. This means that at every call of the command, the server returns an updated cursor that the user needs to use as the cursor argument in the next call.\n\nAn iteration starts when the cursor is set to 0, and terminates when the cursor returned by the server is 0. The following is an example of SCAN iteration:\n\n[code example]\n\nIn the example above, the first call uses zero as a cursor, to start the iteration. The second call uses the cursor returned by the previous call as the first element of the reply, that is, 17.\n\nAs you can see the **SCAN return value** is an array of two values: the first value is the new cursor to use in the next call, the second value is an array of elements.\n\nSince in the second call the returned cursor is 0, the server signaled to the caller that the iteration finished, and the collection was completely explored. Starting an iteration with a cursor value of 0, and calling `SCAN` until the returned cursor is 0 again is called a **full iteration**."
    },
    {
      "id": "return-value",
      "title": "Return value",
      "role": "returns",
      "text": "`SCAN`, [`SSCAN`](https://redis.io/docs/latest/commands/sscan), [`HSCAN`](https://redis.io/docs/latest/commands/hscan) and [`ZSCAN`](https://redis.io/docs/latest/commands/zscan) return a two element multi-bulk reply, where the first element is a string representing an unsigned 64 bit number (the cursor), and the second element is a multi-bulk with an array of elements.\n\n* `SCAN` array of elements is a list of keys.\n* [`SSCAN`](https://redis.io/docs/latest/commands/sscan) array of elements is a list of Set members.\n* [`HSCAN`](https://redis.io/docs/latest/commands/hscan) array of elements contain two elements, a field and a value, for every returned element of the Hash.\n* [`ZSCAN`](https://redis.io/docs/latest/commands/zscan) array of elements contain two elements, a member and its associated score, for every returned element of the Sorted Set."
    },
    {
      "id": "scan-guarantees",
      "title": "Scan guarantees",
      "role": "content",
      "text": "The `SCAN` command, and the other commands in the `SCAN` family, are able to provide to the user a set of guarantees associated to full iterations.\n\n* A full iteration always retrieves all the elements that were present in the collection from the start to the end of a full iteration. This means that if a given element is inside the collection when an iteration is started, and is still there when an iteration terminates, then at some point `SCAN` returned it to the user.\n* A full iteration never returns any element that was NOT present in the collection from the start to the end of a full iteration. So if an element was removed before the start of an iteration, and is never added back to the collection for all the time an iteration lasts, `SCAN` ensures that this element will never be returned.\n\nHowever because `SCAN` has very little state associated (just the cursor) it has the following drawbacks:\n\n* A given element may be returned multiple times. It is up to the application to handle the case of duplicated elements, for example only using the returned elements in order to perform operations that are safe when re-applied multiple times.\n* Elements that were not constantly present in the collection during a full iteration, may be returned or not: it is undefined."
    },
    {
      "id": "number-of-elements-returned-at-every-scan-call",
      "title": "Number of elements returned at every SCAN call",
      "role": "content",
      "text": "`SCAN` family functions do not guarantee that the number of elements returned per call are in a given range. The commands are also allowed to return zero elements, and the client should not consider the iteration complete as long as the returned cursor is not zero.\n\nHowever the number of returned elements is reasonable, that is, in practical terms `SCAN` may return a maximum number of elements in the order of a few tens of elements when iterating a large collection, or may return all the elements of the collection in a single call when the iterated collection is small enough to be internally represented as an encoded data structure (this happens for small Sets, Hashes and Sorted Sets).\n\nHowever there is a way for the user to tune the order of magnitude of the number of returned elements per call using the **COUNT** option."
    },
    {
      "id": "the-count-option",
      "title": "The COUNT option",
      "role": "content",
      "text": "While `SCAN` does not provide guarantees about the number of elements returned at every iteration, it is possible to empirically adjust the behavior of `SCAN` using the **COUNT** option. Basically with COUNT the user specifies the *amount of work that should be done at every call in order to retrieve elements from the collection*. This is **just a hint** for the implementation, however generally speaking this is what you could expect most of the times from the implementation.\n\n* The default `COUNT` value is 10.\n* When iterating the key space, or a Set, Hash or Sorted Set that is big enough to be represented by a hash table, assuming no **MATCH** option is used, the server will usually return *count* or a few more than *count* elements per call. Please check the *why SCAN may return all the elements at once* section later in this document.\n* When iterating Sets encoded as intsets (small sets composed of just integers), or Hashes and Sorted Sets encoded as ziplists (small hashes and sets composed of small individual values), usually all the elements are returned in the first `SCAN` call regardless of the `COUNT` value.\n\nImportant: **there is no need to use the same COUNT value** for every iteration. The caller is free to change the count from one iteration to the other as required, as long as the cursor passed in the next call is the one obtained in the previous call to the command."
    },
    {
      "id": "the-match-option",
      "title": "The MATCH option",
      "role": "content",
      "text": "It is possible to only iterate elements matching a given glob-style pattern, similarly to the behavior of the [`KEYS`](https://redis.io/docs/latest/commands/keys) command that takes a pattern as its only argument.\n\nTo do so, just append the `MATCH <pattern>` arguments at the end of the `SCAN` command (it works with all the `SCAN` family commands).\n\nThis is an example of iteration using **MATCH**:\n\nSet iteration: Iterate set members with pattern matching using SSCAN MATCH (cursor-based iteration, non-blocking)\n\n**Difficulty:** Intermediate\n\n**Commands:** SADD, SSCAN\n\n**Complexity:**\n- SADD: O(1)\n- SSCAN: O(1)\n\n**Available in:** Redis CLI, C, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C\n\n[code example]\n\n##### C#\n\n\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##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nIt is important to note that the **MATCH** filter is applied after elements are retrieved from the collection, just before returning data to the client. This means that if the pattern matches very little elements inside the collection, `SCAN` will likely return no elements in most iterations. An example is shown below:\n\nKeyspace iteration: Iterate database keys with pattern matching using SCAN MATCH and COUNT (demonstrates cursor iteration with sparse results)\n\n**Difficulty:** Intermediate\n\n**Commands:** SCAN\n\n**Complexity:**\n- SCAN: O(1)\n\n**Available in:** Redis CLI, C, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C\n\n[code example]\n\n##### C#\n\n\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##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nAs you can see most of the calls returned zero elements, but the last call where a `COUNT` of 1000 was used in order to force the command to do more scanning for that iteration.\n\nWhen using [Redis Cluster](https://redis.io/docs/latest/operate/oss_and_stack/management/scaling), the search is optimized for patterns that imply a single slot.\nIf a pattern can only match keys of one slot,\nRedis only iterates over keys in that slot, rather than the whole database,\nwhen searching for keys matching the pattern.\nFor example, with the pattern `{a}h*llo`, Redis would only try to match it with the keys in slot 15495, which hash tag `{a}` implies.\nTo use pattern with hash tag, see [Hash tags](https://redis.io/docs/latest/operate/oss_and_stack/reference/cluster-spec#hash-tags) in the Cluster specification for more information."
    },
    {
      "id": "the-type-option",
      "title": "The TYPE option",
      "role": "content",
      "text": "You can use the `TYPE` option to ask `SCAN` to only return objects that match a given `type`, allowing you to iterate through the database looking for keys of a specific type. The **TYPE** option is only available on the whole-database `SCAN`, not [`HSCAN`](https://redis.io/docs/latest/commands/hscan) or [`ZSCAN`](https://redis.io/docs/latest/commands/zscan) etc.\n\nThe `type` argument is the same string name that the [`TYPE`](https://redis.io/docs/latest/commands/type) command returns. Note a quirk where some Redis types, such as GeoHashes, HyperLogLogs, Bitmaps, and Bitfields, may internally be implemented using other Redis types, such as a string or zset, so can't be distinguished from other keys of that same type by `SCAN`. For example, a ZSET and GEOHASH:\n\nIterate keyspace by type: Iterate database keys filtered by type using SCAN TYPE (filters keys by data type, useful for type-specific operations)\n\n**Difficulty:** Intermediate\n\n**Commands:** GEOADD, ZADD, TYPE, SCAN\n\n**Complexity:**\n- GEOADD: O(log(N)\n- ZADD: O(log(N)\n- TYPE: O(1)\n- SCAN: O(1)\n\n**Available in:** Redis CLI, C, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C\n\n[code example]\n\n##### C#\n\n\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##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nIt is important to note that the **TYPE** filter is also applied after elements are retrieved from the database, so the option does not reduce the amount of work the server has to do to complete a full iteration, and for rare types you may receive no elements in many iterations."
    },
    {
      "id": "the-novalues-option",
      "title": "The NOVALUES option",
      "role": "content",
      "text": "When using [`HSCAN`](https://redis.io/docs/latest/commands/hscan), you can use the `NOVALUES` option to make Redis return only the keys in the hash table without their corresponding values.\n\nHash iteration: Iterate hash fields with optional NOVALUES using HSCAN (returns field-value pairs or fields only)\n\n**Difficulty:** Intermediate\n\n**Commands:** HSET, HSCAN\n\n**Complexity:**\n- HSET: O(1)\n- HSCAN: O(1)\n\n**Available in:** Redis CLI, C, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C\n\n[code example]\n\n##### C#\n\n\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##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]"
    },
    {
      "id": "multiple-parallel-iterations",
      "title": "Multiple parallel iterations",
      "role": "content",
      "text": "It is possible for an infinite number of clients to iterate the same collection at the same time, as the full state of the iterator is in the cursor, that is obtained and returned to the client at every call. No server side state is taken at all."
    },
    {
      "id": "terminating-iterations-in-the-middle",
      "title": "Terminating iterations in the middle",
      "role": "content",
      "text": "Since there is no state server side, but the full state is captured by the cursor, the caller is free to terminate an iteration half-way without signaling this to the server in any way. An infinite number of iterations can be started and never terminated without any issue."
    },
    {
      "id": "calling-scan-with-a-corrupted-cursor",
      "title": "Calling SCAN with a corrupted cursor",
      "role": "content",
      "text": "Calling `SCAN` with a broken, negative, out of range, or otherwise invalid cursor, will result in undefined behavior but never in a crash. What will be undefined is that the guarantees about the returned elements can no longer be ensured by the `SCAN` implementation.\n\nThe only valid cursors to use are:\n\n* The cursor value of 0 when starting an iteration.\n* The cursor returned by the previous call to SCAN in order to continue the iteration."
    },
    {
      "id": "guarantee-of-termination",
      "title": "Guarantee of termination",
      "role": "content",
      "text": "The `SCAN` algorithm is guaranteed to terminate only if the size of the iterated collection remains bounded to a given maximum size, otherwise iterating a collection that always grows may result into `SCAN` to never terminate a full iteration.\n\nThis is easy to see intuitively: if the collection grows there is more and more work to do in order to visit all the possible elements, and the ability to terminate the iteration depends on the number of calls to `SCAN` and its COUNT option value compared with the rate at which the collection grows."
    },
    {
      "id": "why-scan-may-return-all-the-items-of-an-aggregate-data-type-in-a-single-call",
      "title": "Why SCAN may return all the items of an aggregate data type in a single call?",
      "role": "content",
      "text": "In the `COUNT` option documentation, we state that sometimes this family of commands may return all the elements of a Set, Hash or Sorted Set at once in a single call, regardless of the `COUNT` option value. The reason why this happens is that the cursor-based iterator can be implemented, and is useful, only when the aggregate data type that we are scanning is represented as a hash table. However Redis uses a [memory optimization](https://redis.io/docs/latest/operate/oss_and_stack/management/optimization/memory-optimization) where small aggregate data types, until they reach a given amount of items or a given max size of single elements, are represented using a compact single-allocation packed encoding. When this is the case, `SCAN` has no meaningful cursor to return, and must iterate the whole data structure at once, so the only sane behavior it has is to return everything in a call.\n\nHowever once the data structures are bigger and are promoted to use real hash tables, the `SCAN` family of commands will resort to the normal behavior. Note that since this special behavior of returning all the elements is true only for small aggregates, it has no effects on the command complexity or latency. However the exact limits to get converted into real hash tables are [user configurable](https://redis.io/docs/latest/operate/oss_and_stack/management/optimization/memory-optimization), so the maximum number of elements you can see returned in a single call depends on how big an aggregate data type could be and still use the packed representation.\n\nAlso note that this behavior is specific of [`SSCAN`](https://redis.io/docs/latest/commands/sscan), [`HSCAN`](https://redis.io/docs/latest/commands/hscan) and [`ZSCAN`](https://redis.io/docs/latest/commands/zscan). `SCAN` itself never shows this behavior because the key space is always represented by hash tables."
    },
    {
      "id": "further-reading",
      "title": "Further reading",
      "role": "content",
      "text": "For more information about managing keys, please refer to the [The Redis Keyspace](https://redis.io/docs/latest/develop/using-commands/keyspace) tutorial."
    },
    {
      "id": "additional-examples",
      "title": "Additional examples",
      "role": "content",
      "text": "Give the following commands, showing iteration of a hash key, a try in the interactive console:\n\n\nredis> HMSET hash name Jack age 33\nOK\nredis> HSCAN hash 0\n1) \"0\"\n2) 1) \"name\"\n   2) \"Jack\"\n   3) \"age\"\n   4) \"33\""
    },
    {
      "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): specifically, an array with two elements.\n* The first element is a [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings) that represents an unsigned 64-bit number, the cursor.\n* The second element is an [Array reply](../../develop/reference/protocol-spec#arrays) with the names of scanned keys.\n\n**RESP3:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): specifically, an array with two elements.\n* The first element is a [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings) that represents an unsigned 64-bit number, the cursor.\n* The second element is an [Array reply](../../develop/reference/protocol-spec#arrays) with the names of scanned keys."
    }
  ],
  "examples": [
    {
      "id": "scan-basic-usage-ex0",
      "language": "plaintext",
      "code": "> scan 0\n1) \"17\"\n2)  1) \"key:12\"\n    2) \"key:8\"\n    3) \"key:4\"\n    4) \"key:14\"\n    5) \"key:16\"\n    6) \"key:17\"\n    7) \"key:15\"\n    8) \"key:10\"\n    9) \"key:3\"\n   10) \"key:7\"\n   11) \"key:1\"\n> scan 17\n1) \"0\"\n2) 1) \"key:5\"\n   2) \"key:18\"\n   3) \"key:0\"\n   4) \"key:2\"\n   5) \"key:19\"\n   6) \"key:13\"\n   7) \"key:6\"\n   8) \"key:9\"\n   9) \"key:11\"",
      "section_id": "scan-basic-usage"
    },
    {
      "id": "the-match-option-ex0",
      "language": "plaintext",
      "code": "> sadd myset 1 2 3 foo foobar feelsgood\n(integer) 6\n> sscan myset 0 match f*\n1) \"0\"\n2) 1) \"foo\"\n   2) \"feelsgood\"\n   3) \"foobar\"",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex1",
      "language": "c",
      "code": "reply = redisCommand(c, \"SADD myset 1 2 3 foo foobar feelsgood\");\n    printf(\"%lld\\n\", reply->integer);\n    // >>> 6\n    freeReplyObject(reply);\n\n    // SCAN-family replies are a two-element array: the next cursor, then the results.\n    reply = redisCommand(c, \"SSCAN myset 0 MATCH f*\");\n    printf(\"%zu\\n\", reply->element[1]->elements);\n    // >>> 3\n    freeReplyObject(reply);",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex2",
      "language": "go",
      "code": "scan1Result1, err := rdb.SAdd(ctx, \"myset\", \"1\", \"2\", \"3\", \"foo\", \"foobar\", \"feelsgood\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(scan1Result1) // >>> 6\n\n\tscan1Result2, _, err := rdb.SScan(ctx, \"myset\", 0, \"f*\", 0).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tsort.Strings(scan1Result2)\n\tfmt.Println(scan1Result2) // >>> [feelsgood foo foobar]",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex3",
      "language": "java",
      "code": "CompletableFuture<Void> scan1Example = asyncCommands\n                    .sadd(\"myset\", \"1\", \"2\", \"3\", \"foo\", \"foobar\", \"feelsgood\")\n                    .thenCompose(scan1Res1 -> {\n                        System.out.println(scan1Res1);      // >>> 6\n                        return asyncCommands.sscan(\"myset\", ScanArgs.Builder.matches(\"f*\"));\n                    })\n                    .thenAccept(scan1Res2 -> {\n                        List<String> members = new java.util.ArrayList<>(scan1Res2.getValues());\n                        Collections.sort(members);\n                        System.out.println(members);        // >>> [feelsgood, foo, foobar]\n                    })\n                    .toCompletableFuture();",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex4",
      "language": "java",
      "code": "Mono<Void> scan1Example = reactiveCommands\n                    .sadd(\"myset\", \"1\", \"2\", \"3\", \"foo\", \"foobar\", \"feelsgood\")\n                    .flatMap(scan1Res1 -> {\n                        System.out.println(scan1Res1);      // >>> 6\n                        return reactiveCommands.sscan(\"myset\", ScanArgs.Builder.matches(\"f*\"));\n                    })\n                    .doOnNext(scan1Res2 -> {\n                        List<String> members = new java.util.ArrayList<>(scan1Res2.getValues());\n                        Collections.sort(members);\n                        System.out.println(members);        // >>> [feelsgood, foo, foobar]\n                    })\n                    .then();",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex5",
      "language": "java",
      "code": "long scan1Result1 = jedis.sadd(\"myset\", \"1\", \"2\", \"3\", \"foo\", \"foobar\", \"feelsgood\");\n        System.out.println(scan1Result1); // >>> 6\n\n        ScanResult<String> scan1Result2 = jedis.sscan(\n                \"myset\", \"0\", new ScanParams().match(\"f*\")\n        );\n        ArrayList<String> scan1Members = new ArrayList<>(scan1Result2.getResult());\n        Collections.sort(scan1Members);\n        System.out.println(scan1Members); // >>> [feelsgood, foo, foobar]",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex6",
      "language": "javascript",
      "code": "const scan1Res1 = await client.sAdd('myset', ['1', '2', '3', 'foo', 'foobar', 'feelsgood']);\nconsole.log(scan1Res1); // 6\n\nlet scan1Res2 = [];\nfor await (const values of client.sScanIterator('myset', { MATCH: 'f*' })) {\n    scan1Res2 = scan1Res2.concat(values);\n}\nconsole.log(scan1Res2); // ['foo', 'foobar', 'feelsgood']",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex7",
      "language": "javascript",
      "code": "const scan1Res1 = await redis.sadd('myset', '1', '2', '3', 'foo', 'foobar', 'feelsgood');\nconsole.log(scan1Res1); // >>> 6\n\nconst [, scan1Members] = await redis.sscan('myset', 0, 'MATCH', 'f*');\nconsole.log(scan1Members.sort()); // >>> ['feelsgood', 'foo', 'foobar']",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex8",
      "language": "javascript",
      "code": "const scan1Res1 = await client.sAdd('myset', ['1', '2', '3', 'foo', 'foobar', 'feelsgood']);\nconsole.log(scan1Res1); // 6\n\nlet scan1Res2 = [];\nfor await (const values of client.sScanIterator('myset', { MATCH: 'f*' })) {\n    scan1Res2 = scan1Res2.concat(values);\n}\nconsole.log(scan1Res2); // ['foo', 'foobar', 'feelsgood']",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex9",
      "language": "javascript",
      "code": "const scan1Res1 = await redis.sadd('myset', '1', '2', '3', 'foo', 'foobar', 'feelsgood');\nconsole.log(scan1Res1); // >>> 6\n\nconst [, scan1Members] = await redis.sscan('myset', 0, 'MATCH', 'f*');\nconsole.log(scan1Members.sort()); // >>> ['feelsgood', 'foo', 'foobar']",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex10",
      "language": "php",
      "code": "$scan1Result1 = $r->sadd('myset', ['1', '2', '3', 'foo', 'foobar', 'feelsgood']);\n        echo $scan1Result1 . PHP_EOL;                       // >>> 6\n\n        [$scan1Cursor, $scan1Members] = $r->sscan('myset', 0, ['MATCH' => 'f*']);\n        sort($scan1Members);\n        echo implode(', ', $scan1Members) . PHP_EOL;         // >>> feelsgood, foo, foobar",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex11",
      "language": "python",
      "code": "res = r.sadd(\"myset\", *set([1, 2, 3, \"foo\", \"foobar\", \"feelsgood\"]))\nprint(res)\n# >>> 6\n\nres = list(r.sscan_iter(\"myset\", match=\"f*\"))\nprint(res)\n# >>> ['foobar', 'foo', 'feelsgood']",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex12",
      "language": "rust",
      "code": "match r.sadd(\"myset\", &[\"1\", \"2\", \"3\", \"foo\", \"foobar\", \"feelsgood\"]).await {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 6\n            },\n            Err(e) => {\n                println!(\"Error adding to set: {e}\");\n                return;\n            }\n        }\n\n        let res = match r.sscan_match(\"myset\", \"f*\").await {\n            Ok(iter) => {\n                let res: Vec<Result<String, _>> = iter.collect().await;\n                res.into_iter().filter_map(|r| r.ok()).collect::<Vec<String>>()\n            },\n            Err(e) => {\n                println!(\"Error scanning set: {e}\");\n                return;\n            }\n        };\n\n        println!(\"{res:?}\");    // >>> [\"foo\", \"foobar\", \"feelsgood\"]",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex13",
      "language": "rust",
      "code": "match r.sadd(\"myset\", &[\"1\", \"2\", \"3\", \"foo\", \"foobar\", \"feelsgood\"]) {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 6\n            },\n            Err(e) => {\n                println!(\"Error adding to set: {e}\");\n                return;\n            }\n        }\n\n        match r.sscan_match(\"myset\", \"f*\") {\n            Ok(iter) => {\n                let res: Vec<String> = iter.filter_map(|r| r.ok()).collect();\n                println!(\"{res:?}\");    // >>> [\"foo\", \"foobar\", \"feelsgood\"]\n            },\n            Err(e) => {\n                println!(\"Error scanning set: {e}\");\n                return;\n            }\n        }",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex14",
      "language": "plaintext",
      "code": "> scan 0 MATCH *11*\n1) \"288\"\n2) 1) \"key:911\"\n> scan 288 MATCH *11*\n1) \"224\"\n2) (empty list or set)\n> scan 224 MATCH *11*\n1) \"80\"\n2) (empty list or set)\n> scan 80 MATCH *11*\n1) \"176\"\n2) (empty list or set)\n> scan 176 MATCH *11* COUNT 1000\n1) \"0\"\n2)  1) \"key:611\"\n    2) \"key:711\"\n    3) \"key:118\"\n    4) \"key:117\"\n    5) \"key:311\"\n    6) \"key:112\"\n    7) \"key:111\"\n    8) \"key:110\"\n    9) \"key:113\"\n   10) \"key:211\"\n   11) \"key:411\"\n   12) \"key:115\"\n   13) \"key:116\"\n   14) \"key:114\"\n   15) \"key:119\"\n   16) \"key:811\"\n   17) \"key:511\"\n   18) \"key:11\"",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex15",
      "language": "c",
      "code": "// MATCH is applied after elements are fetched, so with the default COUNT most\n    // iterations return few keys or none at all.\n    char cursor[64] = \"0\";\n\n    for (int i = 0; i < 4; i++) {\n        reply = redisCommand(c, \"SCAN %s MATCH *11*\", cursor);\n        snprintf(cursor, sizeof(cursor), \"%s\", reply->element[0]->str);\n        printf(\"%zu\\n\", reply->element[1]->elements);\n        freeReplyObject(reply);\n    }\n\n    // A larger COUNT forces more scanning in a single iteration, so the remaining\n    // matches arrive together. This continues from the cursor reached above.\n    reply = redisCommand(c, \"SCAN %s MATCH *11* COUNT 1000\", cursor);\n    printf(\"%zu\\n\", reply->element[1]->elements);\n    // >>> 18\n    freeReplyObject(reply);",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex16",
      "language": "go",
      "code": "// MATCH is applied after elements are fetched, so with the default COUNT most\n\t// iterations return few keys or none at all.\n\tvar scan2Cursor uint64\n\tvar scan2Keys []string\n\tvar err error\n\tscan2Total := 0\n\n\tfor i := 0; i < 4; i++ {\n\t\tscan2Keys, scan2Cursor, err = rdb.Scan(ctx, scan2Cursor, \"*11*\", 0).Result()\n\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tscan2Total += len(scan2Keys)\n\t}\n\n\t// A larger COUNT forces more scanning in a single iteration, so the remaining\n\t// matches arrive together. This continues from the cursor reached above.\n\tscan2Keys, _, err = rdb.Scan(ctx, scan2Cursor, \"*11*\", 1000).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tscan2Total += len(scan2Keys)\n\n\t// The per-call split isn't guaranteed, but the cumulative total is.\n\tfmt.Println(scan2Total) // >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex17",
      "language": "java",
      "code": "// MATCH is applied after elements are fetched, so with the default COUNT most\n            // iterations return few keys or none at all. Each iteration is awaited because\n            // the next one needs the cursor this one returns.\n            KeyScanCursor<String> scan2Cursor = asyncCommands\n                    .scan(ScanArgs.Builder.matches(\"*11*\")).toCompletableFuture().join();\n            int scan2Total = scan2Cursor.getKeys().size();\n            System.out.println(scan2Cursor.getKeys().size());\n\n            for (int i = 0; i < 3; i++) {\n                scan2Cursor = asyncCommands\n                        .scan(scan2Cursor, ScanArgs.Builder.matches(\"*11*\"))\n                        .toCompletableFuture().join();\n                scan2Total += scan2Cursor.getKeys().size();\n                System.out.println(scan2Cursor.getKeys().size());\n            }\n\n            // A larger COUNT forces more scanning in a single iteration, so the remaining\n            // matches arrive together. This continues from the cursor reached above.\n            scan2Cursor = asyncCommands\n                    .scan(scan2Cursor, ScanArgs.Builder.matches(\"*11*\").limit(1000))\n                    .toCompletableFuture().join();\n            scan2Total += scan2Cursor.getKeys().size();\n            System.out.println(scan2Cursor.getKeys().size());\n\n            // The per-call split isn't guaranteed, but the cumulative total is.\n            System.out.println(scan2Total);   // >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex18",
      "language": "java",
      "code": "// MATCH is applied after elements are fetched, so with the default COUNT most\n            // iterations return few keys or none at all. Each iteration is subscribed to in\n            // turn because the next one needs the cursor this one returns.\n            KeyScanCursor<String> scan2Cursor = reactiveCommands\n                    .scan(ScanArgs.Builder.matches(\"*11*\")).block();\n            int scan2Total = scan2Cursor.getKeys().size();\n            System.out.println(scan2Cursor.getKeys().size());\n\n            for (int i = 0; i < 3; i++) {\n                scan2Cursor = reactiveCommands\n                        .scan(scan2Cursor, ScanArgs.Builder.matches(\"*11*\")).block();\n                scan2Total += scan2Cursor.getKeys().size();\n                System.out.println(scan2Cursor.getKeys().size());\n            }\n\n            // A larger COUNT forces more scanning in a single iteration, so the remaining\n            // matches arrive together. This continues from the cursor reached above.\n            scan2Cursor = reactiveCommands\n                    .scan(scan2Cursor, ScanArgs.Builder.matches(\"*11*\").limit(1000)).block();\n            scan2Total += scan2Cursor.getKeys().size();\n            System.out.println(scan2Cursor.getKeys().size());\n\n            // The per-call split isn't guaranteed, but the cumulative total is.\n            System.out.println(scan2Total);   // >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex19",
      "language": "java",
      "code": "// MATCH is applied after elements are fetched, so with the default COUNT most\n        // iterations return few keys or none at all.\n        String scan2Cursor = \"0\";\n        ScanResult<String> scan2Result;\n        int scan2Total = 0;\n\n        for (int i = 0; i < 4; i++) {\n            scan2Result = jedis.scan(scan2Cursor, new ScanParams().match(\"*11*\"));\n            scan2Cursor = scan2Result.getCursor();\n            scan2Total += scan2Result.getResult().size();\n            System.out.println(scan2Result.getResult().size());\n        }\n\n        // A larger COUNT forces more scanning in a single iteration, so the remaining\n        // matches arrive together. This continues from the cursor reached above.\n        scan2Result = jedis.scan(scan2Cursor, new ScanParams().match(\"*11*\").count(1000));\n        scan2Total += scan2Result.getResult().size();\n        System.out.println(scan2Result.getResult().size());\n\n        // The per-call split isn't guaranteed, but the cumulative total is.\n        System.out.println(scan2Total); // >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex20",
      "language": "javascript",
      "code": "let cursor = '0';\nlet scanResult;\nlet total = 0;\n\nscanResult = await client.scan(cursor, { MATCH: '*11*' });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\nscanResult = await client.scan(scanResult.cursor, { MATCH: '*11*' });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\nscanResult = await client.scan(scanResult.cursor, { MATCH: '*11*' });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\nscanResult = await client.scan(scanResult.cursor, { MATCH: '*11*' });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\nscanResult = await client.scan(scanResult.cursor, { MATCH: '*11*', COUNT: 1000 });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\n// The per-call split isn't guaranteed, but the cumulative total is.\nconsole.log(total);\n// >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex21",
      "language": "javascript",
      "code": "// MATCH filters after the elements are fetched, so most iterations return nothing.\nlet [scan2Cursor, scan2Keys] = await redis.scan(0, 'MATCH', '*11*');\nlet scan2Total = scan2Keys.length;\nconsole.log(scan2Keys.length);\n\nfor (let i = 0; i < 3; i++) {\n  [scan2Cursor, scan2Keys] = await redis.scan(scan2Cursor, 'MATCH', '*11*');\n  scan2Total += scan2Keys.length;\n  console.log(scan2Keys.length);\n}\n\n// A larger COUNT forces more scanning in a single iteration, so the rest of the\n// matches arrive together. The scan continues from the cursor reached above.\n[scan2Cursor, scan2Keys] = await redis.scan(scan2Cursor, 'MATCH', '*11*', 'COUNT', 1000);\nscan2Total += scan2Keys.length;\nconsole.log(scan2Keys.length);\n\n// The per-call split isn't guaranteed, but the cumulative total is.\nconsole.log(scan2Total); // >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex22",
      "language": "javascript",
      "code": "let cursor = '0';\nlet scanResult;\nlet total = 0;\n\nscanResult = await client.scan(cursor, { MATCH: '*11*' });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\nscanResult = await client.scan(scanResult.cursor, { MATCH: '*11*' });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\nscanResult = await client.scan(scanResult.cursor, { MATCH: '*11*' });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\nscanResult = await client.scan(scanResult.cursor, { MATCH: '*11*' });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\nscanResult = await client.scan(scanResult.cursor, { MATCH: '*11*', COUNT: 1000 });\ntotal += scanResult.keys.length;\nconsole.log(scanResult.cursor, scanResult.keys);\n\n// The per-call split isn't guaranteed, but the cumulative total is.\nconsole.log(total);\n// >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex23",
      "language": "javascript",
      "code": "// MATCH filters after the elements are fetched, so most iterations return nothing.\nlet [scan2Cursor, scan2Keys] = await redis.scan(0, 'MATCH', '*11*');\nlet scan2Total = scan2Keys.length;\nconsole.log(scan2Keys.length);\n\nfor (let i = 0; i < 3; i++) {\n  [scan2Cursor, scan2Keys] = await redis.scan(scan2Cursor, 'MATCH', '*11*');\n  scan2Total += scan2Keys.length;\n  console.log(scan2Keys.length);\n}\n\n// A larger COUNT forces more scanning in a single iteration, so the rest of the\n// matches arrive together. The scan continues from the cursor reached above.\n[scan2Cursor, scan2Keys] = await redis.scan(scan2Cursor, 'MATCH', '*11*', 'COUNT', 1000);\nscan2Total += scan2Keys.length;\nconsole.log(scan2Keys.length);\n\n// The per-call split isn't guaranteed, but the cumulative total is.\nconsole.log(scan2Total); // >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex24",
      "language": "php",
      "code": "// MATCH is applied after elements are fetched, so with the default COUNT most\n        // iterations return few keys or none at all.\n        $scan2Cursor = 0;\n        $scan2Total = 0;\n\n        for ($i = 0; $i < 4; $i++) {\n            [$scan2Cursor, $scan2Keys] = $r->scan($scan2Cursor, ['MATCH' => '*11*']);\n            $scan2Total += count($scan2Keys);\n            echo count($scan2Keys) . PHP_EOL;\n        }\n\n        // A larger COUNT forces more scanning in a single iteration, so the remaining\n        // matches arrive together. This continues from the cursor reached above.\n        [$scan2Cursor, $scan2Keys] = $r->scan($scan2Cursor, ['MATCH' => '*11*', 'COUNT' => 1000]);\n        $scan2Total += count($scan2Keys);\n        echo count($scan2Keys) . PHP_EOL;\n\n        // The per-call split isn't guaranteed, but the cumulative total is.\n        echo $scan2Total . PHP_EOL;                          // >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex25",
      "language": "python",
      "code": "total = 0\n\ncursor, keys = r.scan(cursor=0, match='*11*')\ntotal += len(keys)\nprint(cursor, keys)\n\ncursor, keys = r.scan(cursor, match='*11*')\ntotal += len(keys)\nprint(cursor, keys)\n\ncursor, keys = r.scan(cursor, match='*11*')\ntotal += len(keys)\nprint(cursor, keys)\n\ncursor, keys = r.scan(cursor, match='*11*')\ntotal += len(keys)\nprint(cursor, keys)\n\ncursor, keys = r.scan(cursor, match='*11*', count=1000)\ntotal += len(keys)\nprint(cursor, keys)\n\n# The per-call split isn't guaranteed, but the cumulative total is.\nprint(total)\n# >>> 19",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex26",
      "language": "rust",
      "code": "// Note: Rust redis client scan_match returns an iterator, not cursor-based\n        // This simulates the Python cursor-based output but uses the available API\n        let keys = match r.scan_match(\"*11*\").await {\n            Ok(iter) => {\n                let keys: Vec<Result<String, _>> = iter.collect().await;\n                keys.into_iter().filter_map(|r| r.ok()).collect::<Vec<String>>()\n            },\n            Err(e) => {\n                println!(\"Error scanning keys: {e}\");\n                return;\n            }\n        };",
      "section_id": "the-match-option"
    },
    {
      "id": "the-match-option-ex27",
      "language": "rust",
      "code": "// Note: Rust redis client scan_match returns an iterator, not cursor-based\n        // This simulates the Python cursor-based output but uses the available API\n        match r.scan_match(\"*11*\") {\n            Ok(iter) => {\n                let keys: Vec<String> = iter.filter_map(|r| r.ok()).collect();\n            },\n            Err(e) => {\n                println!(\"Error scanning keys: {e}\");\n                return;\n            }\n        }",
      "section_id": "the-match-option"
    },
    {
      "id": "the-type-option-ex0",
      "language": "plaintext",
      "code": "> GEOADD geokey 0 0 value\n(integer) 1\n> ZADD zkey 1000 value\n(integer) 1\n> TYPE geokey\nzset\n> TYPE zkey\nzset\n> SCAN 0 TYPE zset\n1) \"0\"\n2) 1) \"geokey\"\n   2) \"zkey\"",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex1",
      "language": "c",
      "code": "reply = redisCommand(c, \"GEOADD geokey 0 0 value\");\n    printf(\"%lld\\n\", reply->integer);\n    // >>> 1\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"ZADD zkey 1000 value\");\n    printf(\"%lld\\n\", reply->integer);\n    // >>> 1\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"TYPE geokey\");\n    printf(\"%s\\n\", reply->str);\n    // >>> zset\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"TYPE zkey\");\n    printf(\"%s\\n\", reply->str);\n    // >>> zset\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"SCAN 0 TYPE zset\");\n    printf(\"%zu\\n\", reply->element[1]->elements);\n    // >>> 2\n    freeReplyObject(reply);",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex2",
      "language": "go",
      "code": "scan3Result1, err := rdb.GeoAdd(ctx, \"geokey\", &redis.GeoLocation{\n\t\tLongitude: 0, Latitude: 0, Name: \"value\",\n\t}).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(scan3Result1) // >>> 1\n\n\tscan3Result2, err := rdb.ZAdd(ctx, \"zkey\", redis.Z{Score: 1000, Member: \"value\"}).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(scan3Result2) // >>> 1\n\n\tscan3Result3, err := rdb.Type(ctx, \"geokey\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(scan3Result3) // >>> zset\n\n\tscan3Result4, err := rdb.Type(ctx, \"zkey\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(scan3Result4) // >>> zset\n\n\t// A single call isn't guaranteed to find every match, so loop until the cursor\n\t// returns to 0, accumulating matches from every call.\n\tvar scan3Cursor uint64\n\tvar scan3Keys []string\n\tvar scan3Batch []string\n\n\tfor {\n\t\tscan3Batch, scan3Cursor, err = rdb.ScanType(ctx, scan3Cursor, \"\", 0, \"zset\").Result()\n\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tscan3Keys = append(scan3Keys, scan3Batch...)\n\n\t\tif scan3Cursor == 0 {\n\t\t\tbreak\n\t\t}\n\t}\n\n\tsort.Strings(scan3Keys)\n\tfmt.Println(scan3Keys) // >>> [geokey zkey]",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex3",
      "language": "java",
      "code": "long scan3Result1 = asyncCommands.geoadd(\"geokey\", 0, 0, \"value\")\n                    .toCompletableFuture().join();\n            System.out.println(scan3Result1);      // >>> 1\n\n            long scan3Result2 = asyncCommands.zadd(\"zkey\", 1000, \"value\")\n                    .toCompletableFuture().join();\n            System.out.println(scan3Result2);      // >>> 1\n\n            String scan3Result3 = asyncCommands.type(\"geokey\").toCompletableFuture().join();\n            System.out.println(scan3Result3);      // >>> zset\n\n            String scan3Result4 = asyncCommands.type(\"zkey\").toCompletableFuture().join();\n            System.out.println(scan3Result4);      // >>> zset\n\n            // A single call isn't guaranteed to find every match, so loop until\n            // the cursor is finished, accumulating matches from every call.\n            List<String> scan3Keys = new java.util.ArrayList<>();\n            KeyScanCursor<String> scan3Cursor = asyncCommands\n                    .scan(KeyScanArgs.Builder.type(\"zset\")).toCompletableFuture().join();\n            scan3Keys.addAll(scan3Cursor.getKeys());\n            while (!scan3Cursor.isFinished()) {\n                scan3Cursor = asyncCommands\n                        .scan(scan3Cursor, KeyScanArgs.Builder.type(\"zset\"))\n                        .toCompletableFuture().join();\n                scan3Keys.addAll(scan3Cursor.getKeys());\n            }\n            Collections.sort(scan3Keys);\n            System.out.println(scan3Keys);         // >>> [geokey, zkey]",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex4",
      "language": "java",
      "code": "long scan3Result1 = reactiveCommands.geoadd(\"geokey\", 0, 0, \"value\").block();\n            System.out.println(scan3Result1);      // >>> 1\n\n            long scan3Result2 = reactiveCommands.zadd(\"zkey\", 1000, \"value\").block();\n            System.out.println(scan3Result2);      // >>> 1\n\n            String scan3Result3 = reactiveCommands.type(\"geokey\").block();\n            System.out.println(scan3Result3);      // >>> zset\n\n            String scan3Result4 = reactiveCommands.type(\"zkey\").block();\n            System.out.println(scan3Result4);      // >>> zset\n\n            // A single call isn't guaranteed to find every match, so loop until\n            // the cursor is finished, accumulating matches from every call.\n            List<String> scan3Keys = new java.util.ArrayList<>();\n            KeyScanCursor<String> scan3Cursor = reactiveCommands\n                    .scan(KeyScanArgs.Builder.type(\"zset\")).block();\n            scan3Keys.addAll(scan3Cursor.getKeys());\n            while (!scan3Cursor.isFinished()) {\n                scan3Cursor = reactiveCommands\n                        .scan(scan3Cursor, KeyScanArgs.Builder.type(\"zset\")).block();\n                scan3Keys.addAll(scan3Cursor.getKeys());\n            }\n            Collections.sort(scan3Keys);\n            System.out.println(scan3Keys);         // >>> [geokey, zkey]",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex5",
      "language": "java",
      "code": "long scan3Result1 = jedis.geoadd(\"geokey\", 0, 0, \"value\");\n        System.out.println(scan3Result1); // >>> 1\n\n        long scan3Result2 = jedis.zadd(\"zkey\", 1000, \"value\");\n        System.out.println(scan3Result2); // >>> 1\n\n        System.out.println(jedis.type(\"geokey\")); // >>> zset\n        System.out.println(jedis.type(\"zkey\")); // >>> zset\n\n        // A single call isn't guaranteed to find every match, so loop until the cursor\n        // returns to \"0\", accumulating matches from every call.\n        String scan3Cursor = \"0\";\n        ArrayList<String> scan3Keys = new ArrayList<>();\n        do {\n            ScanResult<String> scan3Result3 = jedis.scan(scan3Cursor, new ScanParams(), \"zset\");\n            scan3Cursor = scan3Result3.getCursor();\n            scan3Keys.addAll(scan3Result3.getResult());\n        } while (!scan3Cursor.equals(\"0\"));\n        Collections.sort(scan3Keys);\n        System.out.println(scan3Keys); // >>> [geokey, zkey]",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex6",
      "language": "javascript",
      "code": "const scan3Res1 = await client.geoAdd('geokey', { longitude: 0, latitude: 0, member: 'value' });\nconsole.log(scan3Res1); // 1\n\nconst scan3Res2 = await client.zAdd('zkey', [{ score: 1000, value: 'value' }]);\nconsole.log(scan3Res2); // 1\n\nconst scan3Res3 = await client.type('geokey');\nconsole.log(scan3Res3); // zset\n\nconst scan3Res4 = await client.type('zkey');\nconsole.log(scan3Res4); // zset\n\n// A single call isn't guaranteed to find every match, so loop until the cursor\n// returns to 0, accumulating matches from every call.\nlet scan3Cursor = '0';\nlet scan3Keys = [];\ndo {\n    const scan3Res5 = await client.scan(scan3Cursor, { TYPE: 'zset' });\n    scan3Cursor = scan3Res5.cursor;\n    scan3Keys = scan3Keys.concat(scan3Res5.keys);\n} while (scan3Cursor !== '0');\nconsole.log(scan3Keys.sort()); // ['geokey', 'zkey']",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex7",
      "language": "javascript",
      "code": "const scan3Res1 = await redis.geoadd('geokey', '0', '0', 'value');\nconsole.log(scan3Res1); // >>> 1\n\nconst scan3Res2 = await redis.zadd('zkey', '1000', 'value');\nconsole.log(scan3Res2); // >>> 1\n\nconsole.log(await redis.type('geokey')); // >>> zset\nconsole.log(await redis.type('zkey')); // >>> zset\n\n// A single call isn't guaranteed to find every match, so loop until the cursor\n// returns to 0, accumulating matches from every call.\nlet scan3Cursor = '0';\nlet scan3Keys = [];\ndo {\n  let scan3Batch;\n  [scan3Cursor, scan3Batch] = await redis.scan(scan3Cursor, 'TYPE', 'zset');\n  scan3Keys = scan3Keys.concat(scan3Batch);\n} while (scan3Cursor !== '0');\nconsole.log(scan3Keys.sort()); // >>> ['geokey', 'zkey']",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex8",
      "language": "javascript",
      "code": "const scan3Res1 = await client.geoAdd('geokey', { longitude: 0, latitude: 0, member: 'value' });\nconsole.log(scan3Res1); // 1\n\nconst scan3Res2 = await client.zAdd('zkey', [{ score: 1000, value: 'value' }]);\nconsole.log(scan3Res2); // 1\n\nconst scan3Res3 = await client.type('geokey');\nconsole.log(scan3Res3); // zset\n\nconst scan3Res4 = await client.type('zkey');\nconsole.log(scan3Res4); // zset\n\n// A single call isn't guaranteed to find every match, so loop until the cursor\n// returns to 0, accumulating matches from every call.\nlet scan3Cursor = '0';\nlet scan3Keys = [];\ndo {\n    const scan3Res5 = await client.scan(scan3Cursor, { TYPE: 'zset' });\n    scan3Cursor = scan3Res5.cursor;\n    scan3Keys = scan3Keys.concat(scan3Res5.keys);\n} while (scan3Cursor !== '0');\nconsole.log(scan3Keys.sort()); // ['geokey', 'zkey']",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex9",
      "language": "javascript",
      "code": "const scan3Res1 = await redis.geoadd('geokey', '0', '0', 'value');\nconsole.log(scan3Res1); // >>> 1\n\nconst scan3Res2 = await redis.zadd('zkey', '1000', 'value');\nconsole.log(scan3Res2); // >>> 1\n\nconsole.log(await redis.type('geokey')); // >>> zset\nconsole.log(await redis.type('zkey')); // >>> zset\n\n// A single call isn't guaranteed to find every match, so loop until the cursor\n// returns to 0, accumulating matches from every call.\nlet scan3Cursor = '0';\nlet scan3Keys = [];\ndo {\n  let scan3Batch;\n  [scan3Cursor, scan3Batch] = await redis.scan(scan3Cursor, 'TYPE', 'zset');\n  scan3Keys = scan3Keys.concat(scan3Batch);\n} while (scan3Cursor !== '0');\nconsole.log(scan3Keys.sort()); // >>> ['geokey', 'zkey']",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex10",
      "language": "php",
      "code": "<?php\nuse PHPUnit\\Framework\\TestCase;\nuse Predis\\Client as PredisClient;\n\nclass CmdsGenericTest\n{\n    public function testCmdsGeneric() {\n        $r = new PredisClient([\n            'scheme'   => 'tcp',\n            'host'     => '127.0.0.1',\n            'port'     => 6379,\n            'password' => '',\n            'database' => 0,\n        ]);\n\n        $existsResult1 = $r->set('key1', 'Hello');\n        echo $existsResult1 . PHP_EOL; // >>> OK\n\n        $existsResult2 = $r->exists('key1');\n        echo $existsResult2 . PHP_EOL; // >>> 1\n\n        $existsResult3 = $r->exists('nosuchkey');\n        echo $existsResult3 . PHP_EOL; // >>> 0\n\n        $existsResult4 = $r->set('key2', 'World');\n        echo $existsResult4 . PHP_EOL; // >>> OK\n\n        $existsResult5 = $r->exists('key1', 'key2', 'nosuchkey');\n        echo $existsResult5 . PHP_EOL; // >>> 2\n\n        $keysResult1 = $r->mset(['firstname' => 'Jack', 'lastname' => 'Stuntman', 'age' => '35']);\n        echo $keysResult1 . PHP_EOL; // >>> OK\n\n        $keysResult2 = $r->keys('*name*');\n        sort($keysResult2);\n        echo implode(', ', $keysResult2) . PHP_EOL; // >>> firstname, lastname\n\n        $keysResult3 = $r->keys('a??');\n        echo implode(', ', $keysResult3) . PHP_EOL; // >>> age\n\n        $keysResult4 = $r->keys('*');\n        sort($keysResult4);\n        echo implode(', ', $keysResult4) . PHP_EOL; // >>> age, firstname, lastname\n\n        $scan1Result1 = $r->sadd('myset', ['1', '2', '3', 'foo', 'foobar', 'feelsgood']);\n        echo $scan1Result1 . PHP_EOL;                       // >>> 6\n\n        [$scan1Cursor, $scan1Members] = $r->sscan('myset', 0, ['MATCH' => 'f*']);\n        sort($scan1Members);\n        echo implode(', ', $scan1Members) . PHP_EOL;         // >>> feelsgood, foo, foobar\n\n\n\n        // MATCH is applied after elements are fetched, so with the default COUNT most\n        // iterations return few keys or none at all.\n        $scan2Cursor = 0;\n        $scan2Total = 0;\n\n        for ($i = 0; $i < 4; $i++) {\n            [$scan2Cursor, $scan2Keys] = $r->scan($scan2Cursor, ['MATCH' => '*11*']);\n            $scan2Total += count($scan2Keys);\n            echo count($scan2Keys) . PHP_EOL;\n        }\n\n        // A larger COUNT forces more scanning in a single iteration, so the remaining\n        // matches arrive together. This continues from the cursor reached above.\n        [$scan2Cursor, $scan2Keys] = $r->scan($scan2Cursor, ['MATCH' => '*11*', 'COUNT' => 1000]);\n        $scan2Total += count($scan2Keys);\n        echo count($scan2Keys) . PHP_EOL;\n\n        // The per-call split isn't guaranteed, but the cumulative total is.\n        echo $scan2Total . PHP_EOL;                          // >>> 19\n\n\n        $scan4Result1 = $r->hset('myhash', 'a', 1, 'b', 2);\n        echo $scan4Result1 . PHP_EOL;                        // >>> 2\n\n        [$scan4Cursor, $scan4Pairs] = $r->hscan('myhash', 0);\n        echo json_encode($scan4Pairs) . PHP_EOL;             // >>> {\"a\":\"1\",\"b\":\"2\"}\n\n        // Redis does not promise a field order, so sort before comparing.\n        [$scan4Cursor, $scan4Fields] = $r->hscan('myhash', 0, ['NOVALUES' => true]);\n        sort($scan4Fields);\n        echo implode(', ', $scan4Fields) . PHP_EOL;          // >>> a, b\n\n\n        echo $r->set('key1', 'Hello') . PHP_EOL;             // >>> OK\n        echo $r->set('key2', 'World') . PHP_EOL;             // >>> OK\n\n        $delResult = $r->del('key1', 'key2', 'key3');\n        echo $delResult . PHP_EOL;                           // >>> 2\n\n\n        echo $r->set('mykey', 'Hello') . PHP_EOL;            // >>> OK\n\n        echo $r->expire('mykey', 10) . PHP_EOL;              // >>> 1\n        echo $r->ttl('mykey') . PHP_EOL;                     // >>> 10\n\n        // Overwriting a key with SET clears its expiry.\n        echo $r->set('mykey', 'Hello World') . PHP_EOL;      // >>> OK\n        echo $r->ttl('mykey') . PHP_EOL;                     // >>> -1\n\n        // XX only sets the expiry when one already exists, so this is a no-op.\n        echo $r->expire('mykey', 10, 'XX') . PHP_EOL;        // >>> 0\n        echo $r->ttl('mykey') . PHP_EOL;                     // >>> -1\n\n        // NX only sets the expiry when there is none, so this one applies.\n        echo $r->expire('mykey', 10, 'NX') . PHP_EOL;        // >>> 1\n        $expireTtl = $r->ttl('mykey');\n        echo $expireTtl . PHP_EOL;                           // >>> 10\n\n\n        echo $r->set('mykey', 'Hello') . PHP_EOL;            // >>> OK\n        echo $r->expire('mykey', 10) . PHP_EOL;              // >>> 1\n\n        $ttlResult = $r->ttl('mykey');\n        echo $ttlResult . PHP_EOL;                           // >>> 10\n\n\n    }\n}",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex11",
      "language": "python",
      "code": "res = r.geoadd(\"geokey\", (0, 0, \"value\"))\nprint(res)\n# >>> 1\n\nres = r.zadd(\"zkey\", {\"value\": 1000})\nprint(res)\n# >>> 1\n\nres = r.type(\"geokey\")\nprint(res)\n# >>> zset\n\nres = r.type(\"zkey\")\nprint(res)\n# >>> zset\n\n# A single call isn't guaranteed to find every match, so loop until the cursor\n# returns to 0, accumulating matches from every call.\ncursor = 0\nscan3_keys = []\nwhile True:\n    cursor, keys = r.scan(cursor=cursor, _type=\"zset\")\n    scan3_keys.extend(keys)\n    if cursor == 0:\n        break\nprint(sorted(scan3_keys))\n# >>> ['geokey', 'zkey']",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex12",
      "language": "rust",
      "code": "match r.geo_add(\"geokey\", &[(0.0, 0.0, \"value\")]).await {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error adding geo location: {e}\");\n                return;\n            }\n        }\n\n        match r.zadd(\"zkey\", \"value\", 1000).await {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error adding to sorted set: {e}\");\n                return;\n            }\n        }\n\n        match r.key_type::<&str, redis::ValueType>(\"geokey\").await {\n            Ok(res) => {\n                println!(\"{res:?}\");    // >>> zset\n            },\n            Err(e) => {\n                println!(\"Error getting key type: {e}\");\n                return;\n            }\n        }\n\n        match r.key_type::<&str, redis::ValueType>(\"zkey\").await {\n            Ok(res) => {\n                println!(\"{res:?}\");    // >>> zset\n            },\n            Err(e) => {\n                println!(\"Error getting key type: {e}\");\n                return;\n            }\n        }\n\n        // Note: Rust redis client doesn't support scan by type directly\n        // We'll manually check the types of our known keys\n        let mut zset_keys = Vec::new();\n        for key in &[\"geokey\", \"zkey\"] {\n            match r.key_type::<&str, redis::ValueType>(key).await {\n                Ok(key_type) => {\n                    if format!(\"{key_type:?}\") == \"ZSet\" {\n                        zset_keys.push(key.to_string());\n                    }\n                },\n                Err(_) => {},\n            }\n        }\n        println!(\"{:?}\", zset_keys);    // >>> [\"zkey\", \"geokey\"]",
      "section_id": "the-type-option"
    },
    {
      "id": "the-type-option-ex13",
      "language": "rust",
      "code": "match r.geo_add(\"geokey\", &[(0.0, 0.0, \"value\")]) {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error adding geo location: {e}\");\n                return;\n            }\n        }\n\n        match r.zadd(\"zkey\", \"value\", 1000) {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error adding to sorted set: {e}\");\n                return;\n            }\n        }\n\n        match r.key_type::<&str, redis::ValueType>(\"geokey\") {\n            Ok(res) => {\n                println!(\"{res:?}\");    // >>> zset\n            },\n            Err(e) => {\n                println!(\"Error getting key type: {e}\");\n                return;\n            }\n        }\n\n        match r.key_type::<&str, redis::ValueType>(\"zkey\") {\n            Ok(res) => {\n                println!(\"{res:?}\");    // >>> zset\n            },\n            Err(e) => {\n                println!(\"Error getting key type: {e}\");\n                return;\n            }\n        }\n\n        // Note: Rust redis client doesn't support scan by type directly\n        // We'll manually check the types of our known keys\n        let mut zset_keys = Vec::new();\n        for key in &[\"geokey\", \"zkey\"] {\n            match r.key_type::<&str, redis::ValueType>(key) {\n                Ok(key_type) => {\n                    if format!(\"{key_type:?}\") == \"ZSet\" {\n                        zset_keys.push(key.to_string());\n                    }\n                },\n                Err(_) => {},\n            }\n        }\n        println!(\"{:?}\", zset_keys);    // >>> [\"zkey\", \"geokey\"]",
      "section_id": "the-type-option"
    },
    {
      "id": "the-novalues-option-ex0",
      "language": "plaintext",
      "code": "> HSET myhash a 1 b 2\nOK\n> HSCAN myhash 0\n1) \"0\"\n2) 1) \"a\"\n   2) \"1\"\n   3) \"b\"\n   4) \"2\"\n> HSCAN myhash 0 NOVALUES\n1) \"0\"\n2) 1) \"a\"\n   2) \"b\"",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex1",
      "language": "c",
      "code": "reply = redisCommand(c, \"HSET myhash a 1 b 2\");\n    printf(\"%lld\\n\", reply->integer);\n    // >>> 2\n    freeReplyObject(reply);\n\n    // Without NOVALUES the results alternate field, value, field, value.\n    reply = redisCommand(c, \"HSCAN myhash 0\");\n    for (size_t i = 0; i < reply->element[1]->elements; i += 2) {\n        printf(\"%s=%s\\n\", reply->element[1]->element[i]->str,\n                           reply->element[1]->element[i + 1]->str);\n    }\n    // >>> a=1\n    // >>> b=2\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"HSCAN myhash 0 NOVALUES\");\n    for (size_t i = 0; i < reply->element[1]->elements; i++) {\n        printf(\"%s\\n\", reply->element[1]->element[i]->str);\n    }\n    // >>> a\n    // >>> b\n    freeReplyObject(reply);",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex2",
      "language": "go",
      "code": "scan4Result1, err := rdb.HSet(ctx, \"myhash\", \"a\", 1, \"b\", 2).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(scan4Result1) // >>> 2\n\n\tscan4Result2, _, err := rdb.HScan(ctx, \"myhash\", 0, \"\", 0).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// HSCAN returns field and value interleaved. Redis does not promise an order, so\n\t// collect the pairs into a map: fmt prints map keys sorted, whatever order they arrived in.\n\tscan4Fields := map[string]string{}\n\n\tfor i := 0; i < len(scan4Result2); i += 2 {\n\t\tscan4Fields[scan4Result2[i]] = scan4Result2[i+1]\n\t}\n\n\tfmt.Println(scan4Fields) // >>> map[a:1 b:2]\n\n\tscan4Result3, _, err := rdb.HScanNoValues(ctx, \"myhash\", 0, \"\", 0).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tsort.Strings(scan4Result3)\n\tfmt.Println(scan4Result3) // >>> [a b]",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex3",
      "language": "java",
      "code": "CompletableFuture<Void> scan4Example = asyncCommands\n                    .hset(\"myhash\", Map.of(\"a\", \"1\", \"b\", \"2\"))\n                    .thenCompose(scan4Res1 -> {\n                        System.out.println(scan4Res1);      // >>> 2\n                        return asyncCommands.hscan(\"myhash\");\n                    })\n                    .thenCompose(scan4Res2 -> {\n                        System.out.println(new java.util.TreeMap<>(scan4Res2.getMap()));\n                        // >>> {a=1, b=2}\n                        return asyncCommands.hscanNovalues(\"myhash\");\n                    })\n                    .thenAccept(scan4Res3 -> {\n                        List<String> fields = new java.util.ArrayList<>(scan4Res3.getKeys());\n                        Collections.sort(fields);\n                        System.out.println(fields);         // >>> [a, b]\n                    })\n                    .toCompletableFuture();",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex4",
      "language": "java",
      "code": "Mono<Void> scan4Example = reactiveCommands\n                    .hset(\"myhash\", Map.of(\"a\", \"1\", \"b\", \"2\"))\n                    .flatMap(scan4Res1 -> {\n                        System.out.println(scan4Res1);      // >>> 2\n                        return reactiveCommands.hscan(\"myhash\");\n                    })\n                    .flatMap(scan4Res2 -> {\n                        System.out.println(new java.util.TreeMap<>(scan4Res2.getMap()));\n                        // >>> {a=1, b=2}\n                        return reactiveCommands.hscanNovalues(\"myhash\");\n                    })\n                    .doOnNext(scan4Res3 -> {\n                        List<String> fields = new java.util.ArrayList<>(scan4Res3.getKeys());\n                        Collections.sort(fields);\n                        System.out.println(fields);         // >>> [a, b]\n                    })\n                    .then();",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex5",
      "language": "java",
      "code": "long scan4Result1 = jedis.hset(\"myhash\", Map.of(\"a\", \"1\", \"b\", \"2\"));\n        System.out.println(scan4Result1); // >>> 2\n\n        ScanResult<Map.Entry<String, String>> scan4Result2 = jedis.hscan(\n                \"myhash\", \"0\", new ScanParams()\n        );\n        ArrayList<String> scan4Pairs = new ArrayList<>();\n        for (Map.Entry<String, String> entry : scan4Result2.getResult()) {\n            scan4Pairs.add(entry.getKey() + \"=\" + entry.getValue());\n        }\n        Collections.sort(scan4Pairs);\n        System.out.println(scan4Pairs); // >>> [a=1, b=2]\n\n        ScanResult<String> scan4Result3 = jedis.hscanNoValues(\n                \"myhash\", \"0\", new ScanParams()\n        );\n        ArrayList<String> scan4Fields = new ArrayList<>(scan4Result3.getResult());\n        Collections.sort(scan4Fields);\n        System.out.println(scan4Fields); // >>> [a, b]",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex6",
      "language": "javascript",
      "code": "const scan4Res1 = await client.hSet('myhash', { a: 1, b: 2 });\nconsole.log(scan4Res1); // 2\n\n// HSCAN doesn't promise a field order, so pair entries into an object rather than\n// relying on position.\nconst scan4Res2 = await client.hScan('myhash', '0');\nconst scan4Pairs = Object.fromEntries(scan4Res2.entries.map((e) => [e.field, e.value]));\nconsole.log(scan4Pairs); // {a: '1', b: '2'}\n\nconst scan4Res3 = await client.hScan('myhash', '0', { COUNT: 10 });\nconst items = scan4Res3.entries.map((item) => item.field).sort()\nconsole.log(items); // ['a', 'b']",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex7",
      "language": "javascript",
      "code": "const scan4Res1 = await redis.hset('myhash', { a: 1, b: 2 });\nconsole.log(scan4Res1); // >>> 2\n\n// HSCAN returns field and value interleaved. Redis does not promise an order, so pair\n// them up into an object rather than relying on the position of each element.\nconst [, scan4Flat] = await redis.hscan('myhash', 0);\nconst scan4Pairs = Object.fromEntries(\n  scan4Flat.reduce((acc, v, i) => (i % 2 ? acc : [...acc, [v, scan4Flat[i + 1]]]), [])\n);\nconsole.log(scan4Pairs); // >>> { a: '1', b: '2' }\n\nconst [, scan4Fields] = await redis.hscan('myhash', 0, 'NOVALUES');\nconsole.log(scan4Fields.sort()); // >>> [ 'a', 'b' ]",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex8",
      "language": "javascript",
      "code": "const scan4Res1 = await client.hSet('myhash', { a: 1, b: 2 });\nconsole.log(scan4Res1); // 2\n\n// HSCAN doesn't promise a field order, so pair entries into an object rather than\n// relying on position.\nconst scan4Res2 = await client.hScan('myhash', '0');\nconst scan4Pairs = Object.fromEntries(scan4Res2.entries.map((e) => [e.field, e.value]));\nconsole.log(scan4Pairs); // {a: '1', b: '2'}\n\nconst scan4Res3 = await client.hScan('myhash', '0', { COUNT: 10 });\nconst items = scan4Res3.entries.map((item) => item.field).sort()\nconsole.log(items); // ['a', 'b']",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex9",
      "language": "javascript",
      "code": "const scan4Res1 = await redis.hset('myhash', { a: 1, b: 2 });\nconsole.log(scan4Res1); // >>> 2\n\n// HSCAN returns field and value interleaved. Redis does not promise an order, so pair\n// them up into an object rather than relying on the position of each element.\nconst [, scan4Flat] = await redis.hscan('myhash', 0);\nconst scan4Pairs = Object.fromEntries(\n  scan4Flat.reduce((acc, v, i) => (i % 2 ? acc : [...acc, [v, scan4Flat[i + 1]]]), [])\n);\nconsole.log(scan4Pairs); // >>> { a: '1', b: '2' }\n\nconst [, scan4Fields] = await redis.hscan('myhash', 0, 'NOVALUES');\nconsole.log(scan4Fields.sort()); // >>> [ 'a', 'b' ]",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex10",
      "language": "php",
      "code": "$scan4Result1 = $r->hset('myhash', 'a', 1, 'b', 2);\n        echo $scan4Result1 . PHP_EOL;                        // >>> 2\n\n        [$scan4Cursor, $scan4Pairs] = $r->hscan('myhash', 0);\n        echo json_encode($scan4Pairs) . PHP_EOL;             // >>> {\"a\":\"1\",\"b\":\"2\"}\n\n        // Redis does not promise a field order, so sort before comparing.\n        [$scan4Cursor, $scan4Fields] = $r->hscan('myhash', 0, ['NOVALUES' => true]);\n        sort($scan4Fields);\n        echo implode(', ', $scan4Fields) . PHP_EOL;          // >>> a, b",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex11",
      "language": "python",
      "code": "res = r.hset(\"myhash\", mapping={\"a\": 1, \"b\": 2})\nprint(res)\n# >>> 2\n\ncursor, keys = r.hscan(\"myhash\", 0)\nprint(keys)\n# >>> {'a': '1', 'b': '2'}\n\ncursor, keys = r.hscan(\"myhash\", 0, no_values=True)\nprint(sorted(keys))\n# >>> ['a', 'b']",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex12",
      "language": "rust",
      "code": "match r.hset(\"myhash\", \"a\", \"1\").await {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error setting hash field: {e}\");\n                return;\n            }\n        }\n\n        match r.hset(\"myhash\", \"b\", \"2\").await {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error setting hash fields: {e}\");\n                return;\n            }\n        }\n\n        let fields = match r.hscan(\"myhash\").await {\n            Ok(iter) => {\n                let items: Vec<Result<(String, String), _>> = iter.collect().await;\n                items.into_iter().filter_map(|r| r.ok()).collect::<std::collections::HashMap<String, String>>()\n            },\n            Err(e) => {\n                println!(\"Error scanning hash: {e}\");\n                return;\n            }\n        };\n\n        println!(\"{fields:?}\");    // >>> {\"a\": \"1\", \"b\": \"2\"}\n\n        // Scan hash keys only (no values)\n        match r.hkeys(\"myhash\").await {\n            Ok(keys) => {\n                let keys: Vec<String> = keys;\n                println!(\"{keys:?}\");    // >>> [\"a\", \"b\"]\n            },\n            Err(e) => {\n                println!(\"Error getting hash keys: {e}\");\n                return;\n            }\n        }",
      "section_id": "the-novalues-option"
    },
    {
      "id": "the-novalues-option-ex13",
      "language": "rust",
      "code": "match r.hset(\"myhash\", \"a\", \"1\") {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error setting hash field: {e}\");\n                return;\n            }\n        }\n\n        match r.hset(\"myhash\", \"b\", \"2\") {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error setting hash fields: {e}\");\n                return;\n            }\n        }\n\n        match r.hscan(\"myhash\") {\n            Ok(iter) => {\n                let fields: std::collections::HashMap<String, String> = iter.filter_map(|r| r.ok()).collect();\n                println!(\"{fields:?}\");    // >>> {\"a\": \"1\", \"b\": \"2\"}\n            },\n            Err(e) => {\n                println!(\"Error scanning hash: {e}\");\n                return;\n            }\n        }\n\n        // Scan hash keys only (no values)\n        match r.hkeys(\"myhash\") {\n            Ok(keys) => {\n                let keys: Vec<String> = keys;\n                println!(\"{keys:?}\");    // >>> [\"a\", \"b\"]\n            },\n            Err(e) => {\n                println!(\"Error getting hash keys: {e}\");\n                return;\n            }\n        }",
      "section_id": "the-novalues-option"
    }
  ]
}
