{
  "schema_version": 2,
  "id": "commands/bitrangeintarray",
  "title": "BITRANGEINTARRAY",
  "url": "https://redis.io/docs/latest/commands/bitrangeintarray/",
  "summary": "Returns the offsets of the set or clear bits in a range of a bitmap.",
  "since": "8.12.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-11-23T16:05:50+01:00",
  "page_type": "content",
  "content_hash": "9e8ae8b5755a8e79bbe683dbbafddaf334bcb6e5a0b9b49d0eb23622b1a69845",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Returns set-bit offsets within a bitmap range in ascending order. Use `ZEROS`\nto return clear-bit offsets instead. The command reads strings and native bitmaps\nregardless of `bitmap-default-roaring`, without changing the stored value.\n\nOffsets use the same numbering as [`GETBIT`](https://redis.io/docs/latest/commands/getbit):\nbit `0` is the most significant bit of the first byte. Returned offsets are\nalways bit offsets, including when the range uses `BYTE` units."
    },
    {
      "id": "reply-size",
      "title": "Reply size",
      "role": "content",
      "text": "> [!WARNING]\n> Without `LIMIT`, `BITRANGEINTARRAY` returns every matching offset, so the\n> reply grows with the number of results rather than with the size of the key.\n> With `ZEROS` on a sparse string, the number of offsets can approach 8 × the\n> string length, so a small key can block the server and exhaust memory.\n> Paginate with `LIMIT`. For roles exposed to low-risk clients, deny\n> `-bitrangeintarray` or set a `client-output-buffer-limit`."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe key that holds a string or native bitmap.\n\n</details>\n\n<details open><summary><code>start</code></summary>\n\nThe first byte or bit offset in the range, inclusive. The default unit is `BYTE`.\nNegative indexes count from the end of the value, as in\n[`BITCOUNT`](https://redis.io/docs/latest/commands/bitcount).\n\n</details>\n\n<details open><summary><code>end</code></summary>\n\nThe last byte or bit offset in the range, inclusive. Negative indexes count from\nthe end: `-1` selects the final byte, or the final bit with `BIT`.\nUse `0 -1` to cover the whole value.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>BYTE | BIT</code></summary>\n\nThe unit for `start` and `end`. `BYTE` is the default. The range selects positions\nin the stored value, not ranks in the returned array.\n\n</details>\n\n<details open><summary><code>LIMIT count</code></summary>\n\nReturn the lowest matching offsets in the range. With `BIT`, the reply contains\nat most `count` offsets. With `BYTE`, the command also returns the remaining\nmatching offsets in the byte containing the `count`th match. The reply can\ntherefore contain up to `count + 7` offsets.\n\n`LIMIT 0` returns an empty array. A negative count is an error. Without `LIMIT`,\nthe command returns every matching offset in the range.\n\n</details>\n\n<details open><summary><code>ZEROS</code></summary>\n\nReturn clear-bit offsets instead of set-bit offsets within the range.\n\n</details>\n\nThe unit, `LIMIT`, and `ZEROS` options can appear in any order after the required\narguments. If an option is repeated, its last value applies."
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> CONFIG SET bitmap-default-roaring yes\nOK\nredis> SETBIT members 1 1\n(integer) 0\nredis> SETBIT members 7 1\n(integer) 0\nredis> SETBIT members 9 1\n(integer) 0\nredis> SETBIT members 30 1\n(integer) 0\nredis> BITRANGEINTARRAY members 0 -1\n1) (integer) 1\n2) (integer) 7\n3) (integer) 9\n4) (integer) 30\nredis> BITRANGEINTARRAY members 1 -1\n1) (integer) 9\n2) (integer) 30\nredis> BITRANGEINTARRAY members 5 10 BIT\n1) (integer) 7\n2) (integer) 9\nredis> BITRANGEINTARRAY members -1 -1\n1) (integer) 30\nredis> BITRANGEINTARRAY members -1 -1 BIT ZEROS\n1) (integer) 31\nredis> BITRANGEINTARRAY members 28 100 BIT ZEROS\n1) (integer) 28\n2) (integer) 29\n3) (integer) 31\nredis> BITRANGEINTARRAY members 0 -1 BIT LIMIT 2\n1) (integer) 1\n2) (integer) 7\nredis> BITRANGEINTARRAY members 8 -1 BIT LIMIT 2\n1) (integer) 9\n2) (integer) 30\nredis> BITRANGEINTARRAY members 0 -1 LIMIT 1\n1) (integer) 1\n2) (integer) 7\nredis> BITRANGEINTARRAY members 1 -1 LIMIT 1\n1) (integer) 9\nredis> BITRANGEINTARRAY members 0 -1 LIMIT 0\n(empty array)\nredis> CONFIG SET bitmap-default-roaring no\nOK\nredis> SET rawbits a\nOK\nredis> BITRANGEINTARRAY rawbits 0 -1\n1) (integer) 1\n2) (integer) 2\n3) (integer) 7\nredis> BITRANGEINTARRAY rawbits 0 -1 ZEROS\n1) (integer) 0\n2) (integer) 3\n3) (integer) 4\n4) (integer) 5\n5) (integer) 6\nredis> GET rawbits\n\"a\"\nredis> TYPE rawbits\nstring"
    },
    {
      "id": "details",
      "title": "Details",
      "role": "content",
      "text": ""
    },
    {
      "id": "ranges-and-clear-bits",
      "title": "Ranges and clear bits",
      "role": "content",
      "text": "`start` and `end` follow `BITCOUNT` range semantics. They accept signed 64-bit\nintegers, and negative indexes count from the logical end of the value in the\nselected unit. Bounds are clamped to the value. A reversed range or a start past\nthe end returns an empty array.\n\nThe range never extends beyond the value's logical length, including when\nusing `ZEROS`. An all-ones value therefore returns an empty array with\n`ZEROS`. This differs from `BITPOS key 0`, which can report the first bit\npast the end. Missing keys and empty values have no matching bits.\n\nWithout `LIMIT`, the number of set-bit offsets equals `BITCOUNT` over the same\nrange. With `ZEROS`, it equals the number of bits in the normalized range minus\nthat count."
    },
    {
      "id": "key-behavior",
      "title": "Key behavior",
      "role": "content",
      "text": "Arguments are validated before looking up the key. With valid arguments, a\nmissing key returns an empty array. Strings and native bitmaps work under either\n`bitmap-default-roaring` setting; other types return `WRONGTYPE`.\n\nStrings are read directly without conversion. Reads leave the stored bytes,\ntype, and expiration unchanged."
    },
    {
      "id": "pagination-and-performance",
      "title": "Pagination and performance",
      "role": "content",
      "text": "Use `LIMIT` to page through matching offsets. Keep the same `end`, unit, and\n`ZEROS` setting for each page. Choose the next `start` from the last returned\nbit offset:\n\n| Unit | Maximum page size | Next `start` |\n|:-----|:------------------|:-------------|\n| `BIT` | `count` | Last offset + 1 |\n| `BYTE` | `count + 7` | floor(last offset / 8) + 1 |\n\nUse a positive count. A page with fewer than `count` results means the range is\nexhausted. A full page might require one final request that returns an empty\narray. Separate calls do not share a snapshot: writes between requests can\nchange the remaining matches. The continuation rules avoid repeating or skipping\noffsets for an unchanged value.\n\nNative bitmaps seek to the start offset and enumerate matching bits. Strings\nscan the requested range in place. `LIMIT` stops the scan once the page is\ncomplete; a range with few matches can still require scanning the whole range.\nNo temporary bitmap or second result array is allocated.\n\nResponse size and serialization cost grow with the number of returned offsets,\nand there is no fixed result-count cap. See [Reply size](#reply-size) for the\namplification when `LIMIT` is omitted. Configured client output-buffer limits\nstill apply; exceeding a limit disconnects the client and stops enumeration.\n\nReturned offsets retain the bitmap's supported range, including values above\n`4294967295` for native bitmaps created with a sufficiently large\n`proto-max-bulk-len`. Clients must preserve the precision of returned integers."
    },
    {
      "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=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> | <span title=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): Offsets of the set bits in the range, or of the clear bits with ZEROS, in ascending order. The range is interpreted as in BITCOUNT: negative indexes count from the end, and the unit defaults to BYTE. Unlike BITPOS, the range never extends past the end of the bitmap, so no clear bits are returned beyond it. With LIMIT, the lowest count offsets in the range are returned. In BYTE units the reply also completes the byte holding the last of them, so it can hold up to 7 more offsets and the next page can start at the following byte. Missing keys and empty ranges return an empty array.\n\n**RESP3:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): Offsets of the set bits in the range, or of the clear bits with ZEROS, in ascending order. The range is interpreted as in BITCOUNT: negative indexes count from the end, and the unit defaults to BYTE. Unlike BITPOS, the range never extends past the end of the bitmap, so no clear bits are returned beyond it. With LIMIT, the lowest count offsets in the range are returned. In BYTE units the reply also completes the byte holding the last of them, so it can hold up to 7 more offsets and the next page can start at the following byte. Missing keys and empty ranges return an empty array."
    },
    {
      "id": "related-topics",
      "title": "Related topics",
      "role": "related",
      "text": "- [Roaring-compressed bitmaps](https://redis.io/docs/latest/develop/data-types/strings/bitmaps#roaring-compressed-bitmaps)"
    }
  ],
  "examples": []
}
