{
  "schema_version": 2,
  "id": "develop/data-types/hashes",
  "title": "Redis hashes",
  "url": "https://redis.io/docs/latest/develop/data-types/hashes/",
  "summary": "Introduction to Redis hashes",
  "aliases": [
    "/data-types/hashes/",
    "/manual/data-types/hashes/",
    "/develop/data-types/hash/"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-10-12T11:04:49+01:00",
  "page_type": "content",
  "content_hash": "b763bd3e13677fb00e008f6af4692a9c1eace741e32cd7b321b11f50774c4806",
  "sections": [
    {
      "id": "hash-command-summary",
      "title": "Hash command summary",
      "role": "content",
      "text": "**33 commands in this group:**\n\n[View all hash commands](https://redis.io/commands/?group=hash)\n\n| Command | Summary | Complexity | Since |\n|---------|---------|------------|-------|\n| [HDEL](https://redis.io/commands/hdel/) | Deletes one or more fields and their values from a hash. Deletes the hash if no fields remain. | O(N) where N is the number of fields to be remo... | 2.0.0 |\n| [HEXISTS](https://redis.io/commands/hexists/) | Determines whether a field exists in a hash. | O(1) | 2.0.0 |\n| [HEXPIRE](https://redis.io/commands/hexpire/) | Set expiry for hash field using relative time to expire (seconds) | O(N) where N is the number of specified fields | 7.4.0 |\n| [HEXPIREAT](https://redis.io/commands/hexpireat/) | Set expiry for hash field using an absolute Unix timestamp (seconds) | O(N) where N is the number of specified fields | 7.4.0 |\n| [HEXPIRETIME](https://redis.io/commands/hexpiretime/) | Returns the expiration time of a hash field as a Unix timestamp, in seconds. | O(N) where N is the number of specified fields | 7.4.0 |\n| [HGET](https://redis.io/commands/hget/) | Returns the value of a field in a hash. | O(1) | 2.0.0 |\n| [HGETALL](https://redis.io/commands/hgetall/) | Returns all fields and values in a hash. | O(N) where N is the size of the hash. | 2.0.0 |\n| [HGETDEL](https://redis.io/commands/hgetdel/) | Returns the value of a field and deletes it from the hash. | O(N) where N is the number of specified fields | 8.0.0 |\n| [HGETEX](https://redis.io/commands/hgetex/) | Get the value of one or more fields of a given hash key, and optionally set their expiration. | O(N) where N is the number of specified fields | 8.0.0 |\n| [HIMPORT](https://redis.io/commands/himport/) | A container for session-based hash import commands using fieldsets. | Depends on subcommand. | 8.10.0 |\n\n#### Hash command summary (part 2)\n\n| Command | Summary | Complexity | Since |\n|---------|---------|------------|-------|\n| [HIMPORT DISCARD](https://redis.io/commands/himport-discard/) | Removes a single session-local fieldset by name. | O(N) where N is the number of session-local fie... | 8.10.0 |\n| [HIMPORT DISCARDALL](https://redis.io/commands/himport-discardall/) | Removes all session-local fieldsets for the connection. | O(N) where N is the number of session-local fie... | 8.10.0 |\n| [HIMPORT PREPARE](https://redis.io/commands/himport-prepare/) | Defines a session-local fieldset that maps a name to a sorted set of field names. | O(N*log(N)) where N is the number of fields. | 8.10.0 |\n| [HIMPORT SET](https://redis.io/commands/himport-set/) | Creates a fieldset-based hash from values supplied in the order matching a previously prepared fieldset. | O(N) where N is the number of fields in the fie... | 8.10.0 |\n| [HINCRBY](https://redis.io/commands/hincrby/) | Increments the integer value of a field in a hash by a number. Uses 0 as initial value if the field doesn't exist. | O(1) | 2.0.0 |\n| [HINCRBYFLOAT](https://redis.io/commands/hincrbyfloat/) | Increments the floating point value of a field by a number. Uses 0 as initial value if the field doesn't exist. | O(1) | 2.6.0 |\n| [HKEYS](https://redis.io/commands/hkeys/) | Returns all fields in a hash. | O(N) where N is the size of the hash. | 2.0.0 |\n| [HLEN](https://redis.io/commands/hlen/) | Returns the number of fields in a hash. | O(1) | 2.0.0 |\n| [HMGET](https://redis.io/commands/hmget/) | Returns the values of all fields in a hash. | O(N) where N is the number of fields being requ... | 2.0.0 |\n| [HMSET](https://redis.io/commands/hmset/) | Sets the values of multiple fields. | O(N) where N is the number of fields being set. | 2.0.0 |\n\n#### Hash command summary (part 3)\n\n| Command | Summary | Complexity | Since |\n|---------|---------|------------|-------|\n| [HPERSIST](https://redis.io/commands/hpersist/) | Removes the expiration time for each specified field | O(N) where N is the number of specified fields | 7.4.0 |\n| [HPEXPIRE](https://redis.io/commands/hpexpire/) | Set expiry for hash field using relative time to expire (milliseconds) | O(N) where N is the number of specified fields | 7.4.0 |\n| [HPEXPIREAT](https://redis.io/commands/hpexpireat/) | Set expiry for hash field using an absolute Unix timestamp (milliseconds) | O(N) where N is the number of specified fields | 7.4.0 |\n| [HPEXPIRETIME](https://redis.io/commands/hpexpiretime/) | Returns the expiration time of a hash field as a Unix timestamp, in msec. | O(N) where N is the number of specified fields | 7.4.0 |\n| [HPTTL](https://redis.io/commands/hpttl/) | Returns the TTL in milliseconds of a hash field. | O(N) where N is the number of specified fields | 7.4.0 |\n| [HRANDFIELD](https://redis.io/commands/hrandfield/) | Returns one or more random fields from a hash. | O(N) where N is the number of fields returned | 6.2.0 |\n| [HSCAN](https://redis.io/commands/hscan/) | Iterates over fields and values of a hash. | O(1) for every call. O(N) for a complete iterat... | 2.8.0 |\n| [HSET](https://redis.io/commands/hset/) | Creates or modifies the value of a field in a hash. | O(1) for each field/value pair added, so O(N) t... | 2.0.0 |\n| [HSETEX](https://redis.io/commands/hsetex/) | Set the value of one or more fields of a given hash key, and optionally set their expiration. | O(N) where N is the number of fields being set. | 8.0.0 |\n| [HSETNX](https://redis.io/commands/hsetnx/) | Sets the value of a field in a hash only when the field doesn't exist. | O(1) | 2.0.0 |\n\n#### Hash command summary (part 4)\n\n| Command | Summary | Complexity | Since |\n|---------|---------|------------|-------|\n| [HSTRLEN](https://redis.io/commands/hstrlen/) | Returns the length of the value of a field. | O(1) | 3.2.0 |\n| [HTTL](https://redis.io/commands/httl/) | Returns the TTL in seconds of a hash field. | O(N) where N is the number of specified fields | 7.4.0 |\n| [HVALS](https://redis.io/commands/hvals/) | Returns all values in a hash. | O(N) where N is the size of the hash. | 2.0.0 |\n\n\n\nRedis hashes are record types structured as collections of field-value pairs.\nYou can use hashes to represent basic objects and to store groupings of counters, among other things.\n\nFoundational: Set and retrieve hash fields using HSET and HGET (overwrites existing field values)\n\n**Commands:** HSET, HGET, HGETALL\n\n**Complexity:**\n- HSET: O(1)\n- HGET: O(1)\n- HGETALL: O(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nWhile hashes are handy to represent *objects*, actually the number of fields you can\nput inside a hash has no practical limits (other than available memory), so you can use\nhashes in many different ways inside your application.\n\nThe command [`HSET`](https://redis.io/docs/latest/commands/hset) sets multiple fields of the hash, while [`HGET`](https://redis.io/docs/latest/commands/hget) retrieves\na single field. [`HMGET`](https://redis.io/docs/latest/commands/hmget) is similar to [`HGET`](https://redis.io/docs/latest/commands/hget) but returns an array of values:\n\nRetrieve multiple field values from a hash using HMGET when you need to reduce round trips to the server\n\n**Builds upon:** set_get_all\n\n**Commands:** DEL, HSET, HMGET\n\n**Complexity:**\n- DEL: O(N)\n- HSET: O(1)\n- HMGET: O(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nThere are commands that are able to perform operations on individual fields\nas well, like [`HINCRBY`](https://redis.io/docs/latest/commands/hincrby):\n\nIncrement hash field values for counters using HINCRBY (creates field if missing, initializes to 0)\n\n**Builds upon:** set_get_all\n\n**Commands:** DEL, HSET, HINCRBY\n\n**Complexity:**\n- DEL: O(N)\n- HSET: O(1)\n- HINCRBY: O(1)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nYou can find the [full list of hash commands in the documentation](/commands?group=hash).\n\nIt is worth noting that small hashes (i.e., a few elements with small values) are\nencoded in special way in memory that make them very memory efficient."
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "* Store counters for the number of times bike:1 has been ridden, has crashed, or has changed owners:\nPractical pattern: Combine HINCRBY and HMGET to track multiple counters when you need atomic updates across multiple fields\n\n**Difficulty:** Intermediate\n\n**Builds upon:** hincrby, hmget\n\n**Commands:** HINCRBY, HGET, HMGET\n\n**Complexity:**\n- HINCRBY: O(1)\n- HGET: O(1)\n- HMGET: O(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]"
    },
    {
      "id": "field-expiration",
      "title": "Field expiration",
      "role": "content",
      "text": "Redis 7.4 introduced the ability to specify an expiration time or a time-to-live (TTL) value for individual hash fields.\nThis capability is comparable to [key expiration](https://redis.io/docs/latest/develop/using-commands/keyspace#key-expiration) and includes a number of similar commands.\n\nUse the following commands to set either an exact expiration time or a TTL value for specific fields:\n\n* [`HEXPIRE`](https://redis.io/docs/latest/commands/hexpire): set the remaining TTL in seconds.\n* [`HPEXPIRE`](https://redis.io/docs/latest/commands/hpexpire): set the remaining TTL in milliseconds.\n* [`HEXPIREAT`](https://redis.io/docs/latest/commands/hexpireat): set the expiration time to a timestamp[^1] specified in seconds.\n* [`HPEXPIREAT`](https://redis.io/docs/latest/commands/hpexpireat): set the expiration time to a timestamp specified in milliseconds.\n\n[^1]: all timestamps are specified in seconds or milliseconds since the [Unix epoch](https://en.wikipedia.org/wiki/Unix_time).\n\nUse the following commands to retrieve either the exact time when or the remaining TTL until specific fields will expire:\n\n* [`HEXPIRETIME`](https://redis.io/docs/latest/commands/hexpiretime): get the expiration time as a timestamp in seconds.\n* [`HPEXPIRETIME`](https://redis.io/docs/latest/commands/hpexpiretime): get the expiration time as a timestamp in milliseconds.\n* [`HTTL`](https://redis.io/docs/latest/commands/httl): get the remaining TTL in seconds.\n* [`HPTTL`](https://redis.io/docs/latest/commands/hpttl): get the remaining TTL in milliseconds.\n\nUse the following command to remove the expiration of specific fields:\n\n* [`HPERSIST`](https://redis.io/docs/latest/commands/hpersist): remove the expiration.\n\nRedis 8.0 introduced the following commands:\n\n* [`HGETEX`](https://redis.io/docs/latest/commands/hgetex): Get the value of one or more fields of a given hash key and optionally set their expiration time or time-to-live (TTL).\n* [`HSETEX`](https://redis.io/docs/latest/commands/hsetex): Set the value of one or more fields of a given hash key and optionally set their expiration time or time-to-live (TTL)."
    },
    {
      "id": "common-field-expiration-use-cases",
      "title": "Common field expiration use cases",
      "role": "content",
      "text": "1. **Event Tracking**: Use a hash key to store events from the last hour. Set each event's TTL to one hour. Use `HLEN` to count events from the past hour.\n\n1. **Fraud Detection**: Create a hash with hourly counters for events. Set each field's TTL to 48 hours. Query the hash to get the number of events per hour for the last 48 hours.\n\n1. **Customer Session Management**: Store customer data in hash keys. Create a new hash key for each session and add a session field to the customer’s hash key. Expire both the session key and the session field in the customer’s hash key automatically when the session expires.\n\n1. **Active Session Tracking**: Store all active sessions in a hash key. Set each session's TTL to expire automatically after inactivity. Use `HLEN` to count active sessions."
    },
    {
      "id": "field-expiration-examples",
      "title": "Field expiration examples",
      "role": "content",
      "text": "Hash field expiration is supported by the official client libraries. The examples below\ndemonstrate the field expiration commands using a hash that stores sensor data with the\nfollowing structure:\n\n| Field           | Value |\n| :-------------- | :---- |\n| `air_quality`   | 256   |\n| `battery_level` | 89    |\n\nBecause the fields expire, each example recreates the `sensor:sensor1` hash first so that\nit runs on its own.\n\nSet a TTL of 60 seconds for two fields of a hash and then retrieve the remaining TTL for\nthose fields:\n\nField expiration: Set a TTL in seconds on individual hash fields using HEXPIRE, then read the remaining TTL with HTTL\n\n**Difficulty:** Intermediate\n\n**Builds upon:** set_get_all\n\n**Commands:** DEL, HSET, HEXPIRE, HTTL\n\n**Complexity:**\n- DEL: O(N)\n- HSET: O(1)\n- HEXPIRE: O(N)\n- HTTL: O(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nSet a hash field's TTL in milliseconds and then retrieve the remaining TTL in milliseconds:\n\nField expiration: Set a TTL in milliseconds on a hash field using HPEXPIRE, then read the remaining TTL with HPTTL\n\n**Difficulty:** Intermediate\n\n**Builds upon:** set_get_all\n\n**Commands:** DEL, HSET, HPEXPIRE, HPTTL\n\n**Complexity:**\n- DEL: O(N)\n- HSET: O(1)\n- HPEXPIRE: O(N)\n- HPTTL: O(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]\n\n\n\nSet a hash field's expiration to a specific timestamp and then retrieve that expiration\ntime (both as a Unix time in seconds):\n\nField expiration: Set an absolute expiration timestamp on a hash field using HEXPIREAT, then read it back with HEXPIRETIME\n\n**Difficulty:** Intermediate\n\n**Builds upon:** set_get_all\n\n**Commands:** DEL, HSET, HEXPIREAT, HEXPIRETIME\n\n**Complexity:**\n- DEL: O(N)\n- HSET: O(1)\n- HEXPIREAT: O(N)\n- HEXPIRETIME: O(N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), 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##### 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##### 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": "compact-hashes",
      "title": "Compact hashes",
      "role": "content",
      "text": "Redis 8.10 introduced *compact hashes*, a way to reduce the memory used by hashes that share the same field names. When many hashes have the same layout (for example, one hash per user, each with `name`, `email`, and `age`), Redis can store the shared set of field names once and keep only the values, plus a small reference to that set, in each key. This is an internal encoding: existing hash commands keep working exactly as before, with the same semantics and replies. The hash just uses less memory.\n\n**Compact hashes work well when:**\n\n- Many keys share the same, mostly stable set of field names — classic object mapping, such as one hash per user, order, or session. The more keys that share a field set, the greater the memory saving.\n- Reads and value updates stay as fast as on a regular hash. Reading any field (for example, [`HGET`](https://redis.io/docs/latest/commands/hget), [`HGETALL`](https://redis.io/docs/latest/commands/hgetall), or [`HRANDFIELD`](https://redis.io/docs/latest/commands/hrandfield)) and overwriting an existing field's value (`HSET key field value` where `field` already exists) are unaffected.\n\n**Compact hashes are not a good fit when:**\n\n- **Field names change often.** Adding a new field with [`HSET`](https://redis.io/docs/latest/commands/hset) or removing one with [`HDEL`](https://redis.io/docs/latest/commands/hdel) detaches the key from its shared field-name set and re-resolves it against the new set, creating a new one if that layout hasn't been seen before. A workload that constantly adds or removes field names erodes the benefit. Note also that once a hash becomes a compact hash, it stays one for the life of the key: it moves between field-name sets as its fields change, but never reverts to a plain hash.\n- **Field names are unique or highly dynamic per key.** With little sharing, a key ends up with its own field-name set, which carries some metadata overhead. A set used by only a few keys can therefore consume more memory than a plain hash. Compact hashes pay off when hundreds or thousands of keys share a set.\n- **Hashes are very large.** Because a compact hash is transferred as a single blob during replication and slot migration, very large hash keys may reduce or negate the benefit.\n\nThere are two ways to opt in."
    },
    {
      "id": "bulk-import-with-himport",
      "title": "Bulk import with HIMPORT",
      "role": "content",
      "text": "The [`HIMPORT`](https://redis.io/docs/latest/commands/himport) command family lets a client import many hashes that share the same field names efficiently. You declare the shared field names once with [`HIMPORT PREPARE`](https://redis.io/docs/latest/commands/himport-prepare), then create each key with [`HIMPORT SET`](https://redis.io/docs/latest/commands/himport-set) by sending only its values. This reduces network traffic and per-command work compared with running [`HSET`](https://redis.io/docs/latest/commands/hset) once per key, and hints Redis to store the new keys as compact hashes. See [`HIMPORT`](https://redis.io/docs/latest/commands/himport) for the full workflow and its subcommands.\n\nFoundational: Declare shared field names once with HIMPORT PREPARE, then create each hash by sending only its values with HIMPORT SET\n\n**Difficulty:** Intermediate\n\n**Commands:** HIMPORT, HGETALL\n\n**Complexity:**\n- HIMPORT: Depends on subcommand\n- HGETALL: O(N)\n\n**Available in:** Redis CLI, C#, C#, Go, Java, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Ruby\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n\n\nEach key you create this way is an ordinary hash. Note that:\n\n- [`HIMPORT SET`](https://redis.io/docs/latest/commands/himport-set) replaces an existing key rather than merging into it.\n- [`HGETALL`](https://redis.io/docs/latest/commands/hgetall) can return the fields in a different order from the one you declared.\n\nA fieldset belongs to the connection that declared it. Client libraries that support `HIMPORT` track your fieldsets and declare them again on each connection they use, including pooled connections, reconnections, and cluster nodes, so you don't manage this yourself. Some clients, such as Jedis, Lettuce, and StackExchange.Redis, have no prepare method: you create a fieldset object and the client declares it when it's first used. Most client libraries mark their `HIMPORT` support as experimental, so its API might change, and some clients don't support it inside a transaction.\n\nTo import many hashes, send the imports in a [pipeline](https://redis.io/docs/latest/develop/using-commands/pipelining) so they share network round trips instead of waiting for each reply in turn:\n\nBulk ingestion: Pipeline many HIMPORT SET calls that share one fieldset to load a large number of hashes with few network round trips\n\n**Difficulty:** Intermediate\n\n**Builds upon:** himport_basic\n\n**Commands:** HIMPORT, HGET\n\n**Complexity:**\n- HIMPORT: Depends on subcommand\n- HGET: O(1)\n\n**Available in:** Redis CLI, C#, C#, Go, Java, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Ruby\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]"
    },
    {
      "id": "automatic-conversion",
      "title": "Automatic conversion",
      "role": "content",
      "text": "For workloads that can't adopt a new command, Redis can convert eligible hashes to compact hashes on its own, with no code change. All the following settings default to `0` (off) and can be changed at runtime with [`CONFIG SET`](https://redis.io/docs/latest/commands/config-set).\n\n#### On the write path\n\nThese convert hashes created or modified by normal commands (such as [`HSET`](https://redis.io/docs/latest/commands/hset)), so an existing application gains the memory saving with no code change. They take effect lazily, like `hash-max-listpack-entries`: a change applies to a given hash only on its next write, not the moment you run [`CONFIG SET`](https://redis.io/docs/latest/commands/config-set).\n\n| Config | Meaning |\n|---|---|\n| `hash-min-template-entries` | Minimum field count for a hash to be auto-converted to a compact hash on its next write. `0` disables auto-conversion. |\n| `hash-max-template-entries` | Maximum field count for auto-conversion: a hash wider than this is left a plain hash (keeps very wide hashes out of the shared registry). `0` means no upper bound. |\n\nA hash is not converted if it uses [field expiration](#field-expiration), even when its field count meets the minimum. After a hash has been converted, it stays a compact hash even if its field count later grows beyond `hash-max-template-entries`.\n\n#### On RDB load\n\nAn RDB saved before this feature contains only plain hashes. These configs let Redis convert them to compact hashes *as the RDB loads*, so an upgrade reclaims memory without rewriting data. They apply only to RDBs without compact hashes; an RDB that already contains them is loaded as-is, with no load-time conversion. In effect these are one-time upgrade configs: they have no effect once the RDB contains at least one compact hash.\n\n| Config | Meaning |\n|---|---|\n| `hash-rdb-load-min-template-entries` | Minimum field count to convert a plain hash to a compact hash during load. `0` disables load-time conversion. |\n| `hash-rdb-load-max-template-entries` | Maximum field count for load-time conversion. `0` means no upper bound. |\n| `hash-rdb-load-template-disassembly-threshold` | Minimum number of keys that must end up sharing a converted field-name set for it to be kept. `0` keeps every converted set. |\n\nThe disassembly threshold avoids wasting memory on field-name sets shared by only a few keys: at the end of the load, if a set is used by fewer keys than the threshold, those keys are converted back to plain hashes and the shared set is freed. It also acts as a safety valve during the load. Redis tracks how many converted sets are still below the threshold; once at least 1,000 have been created, if more than half of them are still below the threshold, Redis assumes the dataset is a poor fit for compact hashes and stops creating new ones partway through the load. From that point, only hashes whose field set matches one already created during this load are converted; the rest stay plain."
    },
    {
      "id": "performance",
      "title": "Performance",
      "role": "performance",
      "text": "Most Redis hash commands are O(1).\n\nA few commands, such as [`HKEYS`](https://redis.io/docs/latest/commands/hkeys), [`HVALS`](https://redis.io/docs/latest/commands/hvals), [`HGETALL`](https://redis.io/docs/latest/commands/hgetall), and most of the expiration-related commands, are O(n), where _n_ is the number of field-value pairs."
    },
    {
      "id": "limits",
      "title": "Limits",
      "role": "limits",
      "text": "Every hash can store up to 4,294,967,295 (2^32 - 1) field-value pairs.\nIn practice, your hashes are limited only by the overall memory on the VMs hosting your Redis deployment."
    },
    {
      "id": "learn-more",
      "title": "Learn more",
      "role": "related",
      "text": "* [Redis Hashes Explained](https://www.youtube.com/watch?v=-KdITaRkQ-U) is a short, comprehensive video explainer covering Redis hashes.\n* [Redis University's RU101](https://university.redis.com/courses/ru101/) covers Redis hashes in detail."
    }
  ],
  "examples": [
    {
      "id": "hash-command-summary-ex0",
      "language": "plaintext",
      "code": "> HSET bike:1 model Deimos brand Ergonom type 'Enduro bikes' price 4972\n(integer) 4\n> HGET bike:1 model\n\"Deimos\"\n> HGET bike:1 price\n\"4972\"\n> HGETALL bike:1\n1) \"model\"\n2) \"Deimos\"\n3) \"brand\"\n4) \"Ergonom\"\n5) \"type\"\n6) \"Enduro bikes\"\n7) \"price\"\n8) \"4972\"",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex1",
      "language": "csharp",
      "code": "db.HashSet(\"bike:1\", [\n            new(\"model\", \"Deimos\"),\n            new(\"brand\", \"Ergonom\"),\n            new(\"type\", \"Enduro bikes\"),\n            new(\"price\", 4972)\n        ]);\n\n        Console.WriteLine(\"Hash Created\");\n        // Hash Created\n\n        var model = db.HashGet(\"bike:1\", \"model\");\n        Console.WriteLine($\"Model: {model}\");\n        // Model: Deimos\n\n        var price = db.HashGet(\"bike:1\", \"price\");\n        Console.WriteLine($\"Price: {price}\");\n        // Price: 4972\n\n        var bike = db.HashGetAll(\"bike:1\");\n        Console.WriteLine(\"bike:1\");\n        Console.WriteLine(string.Join(\"\\n\", bike.Select(b => $\"{b.Name}: {b.Value}\")));\n        // Bike:1:\n        // model: Deimos\n        // brand: Ergonom\n        // type: Enduro bikes\n        // price: 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex2",
      "language": "go",
      "code": "hashFields := []string{\n\t\t\"model\", \"Deimos\",\n\t\t\"brand\", \"Ergonom\",\n\t\t\"type\", \"Enduro bikes\",\n\t\t\"price\", \"4972\",\n\t}\n\n\tres1, err := rdb.HSet(ctx, \"bike:1\", hashFields).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res1) // >>> 4\n\n\tres2, err := rdb.HGet(ctx, \"bike:1\", \"model\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res2) // >>> Deimos\n\n\tres3, err := rdb.HGet(ctx, \"bike:1\", \"price\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res3) // >>> 4972\n\n\tcmdReturn := rdb.HGetAll(ctx, \"bike:1\")\n\tres4, err := cmdReturn.Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res4)\n\t// >>> map[brand:Ergonom model:Deimos price:4972 type:Enduro bikes]\n\n\ttype BikeInfo struct {\n\t\tModel string `redis:\"model\"`\n\t\tBrand string `redis:\"brand\"`\n\t\tType  string `redis:\"type\"`\n\t\tPrice int    `redis:\"price\"`\n\t}\n\n\tvar res4a BikeInfo\n\n\tif err := cmdReturn.Scan(&res4a); err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"Model: %v, Brand: %v, Type: %v, Price: $%v\\n\",\n\t\tres4a.Model, res4a.Brand, res4a.Type, res4a.Price)\n\t// >>> Model: Deimos, Brand: Ergonom, Type: Enduro bikes, Price: $4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex3",
      "language": "java",
      "code": "Map<String, String> bike1 = new HashMap<>();\n            bike1.put(\"model\", \"Deimos\");\n            bike1.put(\"brand\", \"Ergonom\");\n            bike1.put(\"type\", \"Enduro bikes\");\n            bike1.put(\"price\", \"4972\");\n\n            CompletableFuture<Void> setGetAll = asyncCommands.hset(\"bike:1\", bike1).thenCompose(res1 -> {\n                System.out.println(res1); // >>> 4\n                return asyncCommands.hget(\"bike:1\", \"model\");\n            }).thenCompose(res2 -> {\n                System.out.println(res2); // >>> Deimos\n                return asyncCommands.hget(\"bike:1\", \"price\");\n            }).thenCompose(res3 -> {\n                System.out.println(res3); // >>> 4972\n                return asyncCommands.hgetall(\"bike:1\");\n            })\n                    .thenAccept(System.out::println)\n                    // >>> {type=Enduro bikes, brand=Ergonom, price=4972, model=Deimos}\n                    .toCompletableFuture();",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex4",
      "language": "java",
      "code": "Map<String, String> bike1 = new HashMap<>();\n            bike1.put(\"model\", \"Deimos\");\n            bike1.put(\"brand\", \"Ergonom\");\n            bike1.put(\"type\", \"Enduro bikes\");\n            bike1.put(\"price\", \"4972\");\n\n            Mono<Long> setGetAll = reactiveCommands.hset(\"bike:1\", bike1).doOnNext(result -> {\n                System.out.println(result); // >>> 4\n            });\n\n            setGetAll.block();\n\n            Mono<String> getModel = reactiveCommands.hget(\"bike:1\", \"model\").doOnNext(result -> {\n                System.out.println(result); // >>> Deimos\n            });\n\n            Mono<String> getPrice = reactiveCommands.hget(\"bike:1\", \"price\").doOnNext(result -> {\n                System.out.println(result); // >>> 4972\n            });\n\n            Mono<List<KeyValue<String, String>>> getAll = reactiveCommands.hgetall(\"bike:1\").collectList().doOnNext(result -> {\n                System.out.println(result);\n                // >>> [KeyValue[type, Enduro bikes], KeyValue[brand, Ergonom],\n                // KeyValue[price, 4972], KeyValue[model, Deimos]]\n            });",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex5",
      "language": "java",
      "code": "Map<String, String> bike1 = new HashMap<>();\n      bike1.put(\"model\", \"Deimos\");\n      bike1.put(\"brand\", \"Ergonom\");\n      bike1.put(\"type\", \"Enduro bikes\");\n      bike1.put(\"price\", \"4972\");\n\n      Long res1 = jedis.hset(\"bike:1\", bike1);\n      System.out.println(res1); // 4\n\n      String res2 = jedis.hget(\"bike:1\", \"model\");\n      System.out.println(res2); // Deimos\n\n      String res3 = jedis.hget(\"bike:1\", \"price\");\n      System.out.println(res3); // 4972\n\n      Map<String, String> res4 = jedis.hgetAll(\"bike:1\");\n      System.out.println(res4); // {type=Enduro bikes, brand=Ergonom, price=4972, model=Deimos}",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex6",
      "language": "javascript",
      "code": "const res1 = await client.hSet(\n  'bike:1',\n  {\n    'model': 'Deimos',\n    'brand': 'Ergonom',\n    'type': 'Enduro bikes',\n    'price': 4972,\n  }\n)\nconsole.log(res1) // 4\n\nconst res2 = await client.hGet('bike:1', 'model')\nconsole.log(res2)  // 'Deimos'\n\nconst res3 = await client.hGet('bike:1', 'price')\nconsole.log(res3)  // '4972'\n\nconst res4 = await client.hGetAll('bike:1')\nconsole.log(res4)  \n/*\n{\n  brand: 'Ergonom',\n  model: 'Deimos',\n  price: '4972',\n  type: 'Enduro bikes'\n}\n*/",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex7",
      "language": "php",
      "code": "$res1 = $r->hmset('bike:1', [\n            'model' => 'Deimos',\n            'brand' => 'Ergonom',\n            'type' => 'Enduro bikes',\n            'price' => 4972,\n        ]);\n\n        echo $res1 . PHP_EOL;\n        // >>> 4\n\n        $res2 = $r->hget('bike:1', 'model');\n        echo $res2 . PHP_EOL;\n        // >>> Deimos\n\n        $res3 = $r->hget('bike:1', 'price');\n        echo $res3 . PHP_EOL;\n        // >>> 4972\n\n        $res4 = $r->hgetall('bike:1');\n        echo json_encode($res3) . PHP_EOL;\n        // >>> {\"name\":\"Deimos\",\"brand\":\"Ergonom\",\"type\":\"Enduro bikes\",\"price\":\"4972\"}",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex8",
      "language": "python",
      "code": "res1 = r.hset(\n    \"bike:1\",\n    mapping={\n        \"model\": \"Deimos\",\n        \"brand\": \"Ergonom\",\n        \"type\": \"Enduro bikes\",\n        \"price\": 4972,\n    },\n)\nprint(res1)\n# >>> 4\n\nres2 = r.hget(\"bike:1\", \"model\")\nprint(res2)\n# >>> 'Deimos'\n\nres3 = r.hget(\"bike:1\", \"price\")\nprint(res3)\n# >>> '4972'\n\nres4 = r.hgetall(\"bike:1\")\nprint(res4)\n# >>> {'model': 'Deimos', 'brand': 'Ergonom', 'type': 'Enduro bikes', 'price': '4972'}",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex9",
      "language": "ruby",
      "code": "res1 = r.hset('bike:1', {\n  'model' => 'Deimos',\n  'brand' => 'Ergonom',\n  'type' => 'Enduro bikes',\n  'price' => 4972\n})\nputs res1 # >>> 4\n\nres2 = r.hget('bike:1', 'model')\nputs res2 # >>> Deimos\n\nres3 = r.hget('bike:1', 'price')\nputs res3 # >>> 4972\n\nres4 = r.hgetall('bike:1')\nputs res4.inspect\n# >>> {\"model\" => \"Deimos\", \"brand\" => \"Ergonom\", \"type\" => \"Enduro bikes\", \"price\" => \"4972\"}",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex10",
      "language": "rust",
      "code": "let hash_fields = [\n            (\"model\", \"Deimos\"),\n            (\"brand\", \"Ergonom\"),\n            (\"type\", \"Enduro bikes\"),\n            (\"price\", \"4972\"),\n        ];\n\n        if let Ok(res) = r.hset_multiple(\"bike:1\", &hash_fields).await {\n            let res: String = res;\n            println!(\"{res}\");    // >>> OK\n        }\n\n        match r.hget(\"bike:1\", \"model\").await {\n            Ok(res) => {\n                let res: String = res;\n                println!(\"{res}\");   // >>> Deimos\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1 model: {e}\");\n                return;\n            }\n        };\n\n        match r.hget(\"bike:1\", \"price\").await {\n            Ok(res) => {\n                let res: String = res;\n                println!(\"{res}\");   // >>> 4972\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1 price: {e}\");\n                return;\n            }\n        };\n\n        match r.hgetall(\"bike:1\").await {\n            Ok(res) => {\n                let res: Vec<(String, String)> = res;\n                println!(\"{res:?}\");\n                // >>> [(\"model\", \"Deimos\"), (\"brand\", \"Ergonom\"), (\"type\", \"Enduro bikes\"), (\"price\", \"4972\")]\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1: {e}\");\n                return;\n            }\n        };",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex11",
      "language": "rust",
      "code": "let hash_fields = [\n            (\"model\", \"Deimos\"),\n            (\"brand\", \"Ergonom\"),\n            (\"type\", \"Enduro bikes\"),\n            (\"price\", \"4972\"),\n        ];\n\n        if let Ok(res) = r.hset_multiple(\"bike:1\", &hash_fields) {\n            let res: String = res;\n            println!(\"{res}\");    // >>> OK\n        }\n\n        match r.hget(\"bike:1\", \"model\") {\n            Ok(res) => {\n                let res: String = res;\n                println!(\"{res}\");   // >>> Deimos\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1 model: {e}\");\n                return;\n            }\n        };\n\n        match r.hget(\"bike:1\", \"price\") {\n            Ok(res) => {\n                let res: String = res;\n                println!(\"{res}\");   // >>> 4972\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1 price: {e}\");\n                return;\n            }\n        };\n\n        match r.hgetall(\"bike:1\") {\n            Ok(res) => {\n                let res: Vec<(String, String)> = res;\n                println!(\"{res:?}\");\n                // >>> [(\"model\", \"Deimos\"), (\"brand\", \"Ergonom\"), (\"type\", \"Enduro bikes\"), (\"price\", \"4972\")]\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1: {e}\");\n                return;\n            }\n        };",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex12",
      "language": "plaintext",
      "code": "# Recreate the bike:1 hash so this example runs on its own.\n> DEL bike:1\n(integer) 1\n> HSET bike:1 model Deimos brand Ergonom type 'Enduro bikes' price 4972\n(integer) 4\n> HMGET bike:1 model price no-such-field\n1) \"Deimos\"\n2) \"4972\"\n3) (nil)",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex13",
      "language": "csharp",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n        db.KeyDelete(\"bike:1\");\n        db.HashSet(\"bike:1\", [\n            new(\"model\", \"Deimos\"),\n            new(\"brand\", \"Ergonom\"),\n            new(\"type\", \"Enduro bikes\"),\n            new(\"price\", 4972)\n        ]);\n\n        var values = db.HashGet(\"bike:1\", [\"model\", \"price\"]);\n        Console.WriteLine(string.Join(\" \", values));\n        // Deimos 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex14",
      "language": "go",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n\trdb.Del(ctx, \"bike:1\")\n\thashFields := []string{\n\t\t\"model\", \"Deimos\",\n\t\t\"brand\", \"Ergonom\",\n\t\t\"type\", \"Enduro bikes\",\n\t\t\"price\", \"4972\",\n\t}\n\trdb.HSet(ctx, \"bike:1\", hashFields)\n\n\tcmdReturn := rdb.HMGet(ctx, \"bike:1\", \"model\", \"price\")\n\tres5, err := cmdReturn.Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res5) // >>> [Deimos 4972]\n\n\ttype BikeInfo struct {\n\t\tModel string `redis:\"model\"`\n\t\tBrand string `redis:\"-\"`\n\t\tType  string `redis:\"-\"`\n\t\tPrice int    `redis:\"price\"`\n\t}\n\n\tvar res5a BikeInfo\n\n\tif err := cmdReturn.Scan(&res5a); err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"Model: %v, Price: $%v\\n\", res5a.Model, res5a.Price)\n\t// >>> Model: Deimos, Price: $4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex15",
      "language": "java",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n            CompletableFuture<Void> hmGet = setGetAll\n                    .thenCompose(res4 -> asyncCommands.del(\"bike:1\"))\n                    .thenCompose(delRes -> asyncCommands.hset(\"bike:1\", bike1))\n                    .thenCompose(hsetRes -> asyncCommands.hmget(\"bike:1\", \"model\", \"price\"))\n                    .thenAccept(System.out::println)\n                    // [KeyValue[model, Deimos], KeyValue[price, 4972]]\n                    .toCompletableFuture();",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex16",
      "language": "java",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n            Mono<List<KeyValue<String, String>>> hmGet = reactiveCommands.del(\"bike:1\")\n                    .then(reactiveCommands.hset(\"bike:1\", bike1))\n                    .then(reactiveCommands.hmget(\"bike:1\", \"model\", \"price\").collectList())\n                    .doOnNext(result -> {\n                        System.out.println(result);\n                        // >>> [KeyValue[model, Deimos], KeyValue[price, 4972]]\n                    });",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex17",
      "language": "java",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n      jedis.del(\"bike:1\");\n      jedis.hset(\"bike:1\", bike1);\n\n      List<String> res5 = jedis.hmget(\"bike:1\", \"model\", \"price\");\n      System.out.println(res5); // [Deimos, 4972]",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex18",
      "language": "javascript",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\nawait client.del('bike:1')\nawait client.hSet(\n  'bike:1',\n  {\n    'model': 'Deimos',\n    'brand': 'Ergonom',\n    'type': 'Enduro bikes',\n    'price': 4972,\n  }\n)\n\nconst res5 = await client.hmGet('bike:1', ['model', 'price'])\nconsole.log(res5)  // ['Deimos', '4972']",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex19",
      "language": "php",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n        $r->del('bike:1');\n        $r->hmset('bike:1', [\n            'model' => 'Deimos',\n            'brand' => 'Ergonom',\n            'type' => 'Enduro bikes',\n            'price' => 4972,\n        ]);\n\n        $res5 = $r->hmget('bike:1', ['model', 'price']);\n        echo json_encode($res5) . PHP_EOL;\n        // >>> [\"Deimos\",\"4972\"]",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex20",
      "language": "python",
      "code": "# Recreate the bike:1 hash so this example runs on its own.\nr.delete(\"bike:1\")\nr.hset(\n    \"bike:1\",\n    mapping={\n        \"model\": \"Deimos\",\n        \"brand\": \"Ergonom\",\n        \"type\": \"Enduro bikes\",\n        \"price\": 4972,\n    },\n)\n\nres5 = r.hmget(\"bike:1\", [\"model\", \"price\"])\nprint(res5)\n# >>> ['Deimos', '4972']",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex21",
      "language": "ruby",
      "code": "# Recreate the bike:1 hash so this example runs on its own.\nr.del('bike:1')\nr.hset('bike:1', {\n  'model' => 'Deimos',\n  'brand' => 'Ergonom',\n  'type' => 'Enduro bikes',\n  'price' => 4972\n})\n\nres5 = r.hmget('bike:1', 'model', 'price', 'no-such-field')\nputs res5.inspect # >>> [\"Deimos\", \"4972\", nil]",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex22",
      "language": "rust",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n        let _: () = r.del(\"bike:1\").await.expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"bike:1\",\n            &[(\"model\", \"Deimos\"), (\"brand\", \"Ergonom\"), (\"type\", \"Enduro bikes\"), (\"price\", \"4972\")],\n        ).await.expect(\"Failed to hset\");\n\n        match r.hmget(\"bike:1\", &[\"model\", \"price\"]).await {\n            Ok(res) => {\n                let res: Vec<String> = res;\n                println!(\"{res:?}\");   // >>> [\"Deimos\", \"4972\"]\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1: {e}\");\n                return;\n            }\n        };",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex23",
      "language": "rust",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n        let _: () = r.del(\"bike:1\").expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"bike:1\",\n            &[(\"model\", \"Deimos\"), (\"brand\", \"Ergonom\"), (\"type\", \"Enduro bikes\"), (\"price\", \"4972\")],\n        ).expect(\"Failed to hset\");\n\n        match r.hmget(\"bike:1\", &[\"model\", \"price\"]) {\n            Ok(res) => {\n                let res: Vec<String> = res;\n                println!(\"{res:?}\");   // >>> [\"Deimos\", \"4972\"]\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1: {e}\");\n                return;\n            }\n        };",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex24",
      "language": "plaintext",
      "code": "# Recreate the bike:1 hash so this example runs on its own.\n> DEL bike:1\n(integer) 1\n> HSET bike:1 model Deimos brand Ergonom type 'Enduro bikes' price 4972\n(integer) 4\n> HINCRBY bike:1 price 100\n(integer) 5072\n> HINCRBY bike:1 price -100\n(integer) 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex25",
      "language": "csharp",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n        db.KeyDelete(\"bike:1\");\n        db.HashSet(\"bike:1\", [\n            new(\"model\", \"Deimos\"),\n            new(\"brand\", \"Ergonom\"),\n            new(\"type\", \"Enduro bikes\"),\n            new(\"price\", 4972)\n        ]);\n\n        var newPrice = db.HashIncrement(\"bike:1\", \"price\", 100);\n        Console.WriteLine($\"New price: {newPrice}\");\n        // New price: 5072\n\n        newPrice = db.HashIncrement(\"bike:1\", \"price\", -100);\n        Console.WriteLine($\"New price: {newPrice}\");\n        // New price: 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex26",
      "language": "go",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n\trdb.Del(ctx, \"bike:1\")\n\thashFields := []string{\n\t\t\"model\", \"Deimos\",\n\t\t\"brand\", \"Ergonom\",\n\t\t\"type\", \"Enduro bikes\",\n\t\t\"price\", \"4972\",\n\t}\n\trdb.HSet(ctx, \"bike:1\", hashFields)\n\n\tres6, err := rdb.HIncrBy(ctx, \"bike:1\", \"price\", 100).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res6) // >>> 5072\n\n\tres7, err := rdb.HIncrBy(ctx, \"bike:1\", \"price\", -100).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res7) // >>> 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex27",
      "language": "java",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n            CompletableFuture<Void> hIncrBy = hmGet\n                    .thenCompose(r -> asyncCommands.del(\"bike:1\"))\n                    .thenCompose(delRes -> asyncCommands.hset(\"bike:1\", bike1))\n                    .thenCompose(hsetRes -> asyncCommands.hincrby(\"bike:1\", \"price\", 100))\n                    .thenCompose(res6 -> {\n                        System.out.println(res6); // >>> 5072\n                        return asyncCommands.hincrby(\"bike:1\", \"price\", -100);\n                    })\n                    .thenAccept(System.out::println)\n                    // >>> 4972\n                    .toCompletableFuture();",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex28",
      "language": "java",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n            Mono<Void> hIncrBy = reactiveCommands.del(\"bike:1\")\n                    .then(reactiveCommands.hset(\"bike:1\", bike1))\n                    .then(reactiveCommands.hincrby(\"bike:1\", \"price\", 100)).doOnNext(result -> {\n                System.out.println(result); // >>> 5072\n            }).flatMap(v -> reactiveCommands.hincrby(\"bike:1\", \"price\", -100)).doOnNext(result -> {\n                System.out.println(result); // >>> 4972\n            }).then();",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex29",
      "language": "java",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n      jedis.del(\"bike:1\");\n      jedis.hset(\"bike:1\", bike1);\n\n      Long res6 = jedis.hincrBy(\"bike:1\", \"price\", 100);\n      System.out.println(res6); // 5072\n      Long res7 = jedis.hincrBy(\"bike:1\", \"price\", -100);\n      System.out.println(res7); // 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex30",
      "language": "javascript",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\nawait client.del('bike:1')\nawait client.hSet(\n  'bike:1',\n  {\n    'model': 'Deimos',\n    'brand': 'Ergonom',\n    'type': 'Enduro bikes',\n    'price': 4972,\n  }\n)\n\nconst res6 = await client.hIncrBy('bike:1', 'price', 100)\nconsole.log(res6)  // 5072\nconst res7 = await client.hIncrBy('bike:1', 'price', -100)\nconsole.log(res7)  // 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex31",
      "language": "php",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n        $r->del('bike:1');\n        $r->hmset('bike:1', [\n            'model' => 'Deimos',\n            'brand' => 'Ergonom',\n            'type' => 'Enduro bikes',\n            'price' => 4972,\n        ]);\n\n        $res6 = $r->hincrby('bike:1', 'price', 100);\n        echo $res6 . PHP_EOL;\n        // >>> 5072\n\n        $res7 = $r->hincrby('bike:1', 'price', -100);\n        echo $res7 . PHP_EOL;\n        // >>> 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex32",
      "language": "python",
      "code": "# Recreate the bike:1 hash so this example runs on its own.\nr.delete(\"bike:1\")\nr.hset(\n    \"bike:1\",\n    mapping={\n        \"model\": \"Deimos\",\n        \"brand\": \"Ergonom\",\n        \"type\": \"Enduro bikes\",\n        \"price\": 4972,\n    },\n)\n\nres6 = r.hincrby(\"bike:1\", \"price\", 100)\nprint(res6)\n# >>> 5072\nres7 = r.hincrby(\"bike:1\", \"price\", -100)\nprint(res7)\n# >>> 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex33",
      "language": "ruby",
      "code": "# Recreate the bike:1 hash so this example runs on its own.\nr.del('bike:1')\nr.hset('bike:1', {\n  'model' => 'Deimos',\n  'brand' => 'Ergonom',\n  'type' => 'Enduro bikes',\n  'price' => 4972\n})\n\nres6 = r.hincrby('bike:1', 'price', 100)\nputs res6 # >>> 5072\n\nres7 = r.hincrby('bike:1', 'price', -100)\nputs res7 # >>> 4972",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex34",
      "language": "rust",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n        let _: () = r.del(\"bike:1\").await.expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"bike:1\",\n            &[(\"model\", \"Deimos\"), (\"brand\", \"Ergonom\"), (\"type\", \"Enduro bikes\"), (\"price\", \"4972\")],\n        ).await.expect(\"Failed to hset\");\n\n        if let Ok(res) = r.hincr(\"bike:1\", \"price\", 100).await {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 5072\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1\", \"price\", -100).await {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 4972\n        }",
      "section_id": "hash-command-summary"
    },
    {
      "id": "hash-command-summary-ex35",
      "language": "rust",
      "code": "// Recreate the bike:1 hash so this example runs on its own.\n        let _: () = r.del(\"bike:1\").expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"bike:1\",\n            &[(\"model\", \"Deimos\"), (\"brand\", \"Ergonom\"), (\"type\", \"Enduro bikes\"), (\"price\", \"4972\")],\n        ).expect(\"Failed to hset\");\n\n        if let Ok(res) = r.hincr(\"bike:1\", \"price\", 100) {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 5072\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1\", \"price\", -100) {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 4972\n        }",
      "section_id": "hash-command-summary"
    },
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> HINCRBY bike:1:stats rides 1\n(integer) 1\n> HINCRBY bike:1:stats rides 1\n(integer) 2\n> HINCRBY bike:1:stats rides 1\n(integer) 3\n> HINCRBY bike:1:stats crashes 1\n(integer) 1\n> HINCRBY bike:1:stats owners 1\n(integer) 1\n> HGET bike:1:stats rides\n\"3\"\n> HMGET bike:1:stats owners crashes\n1) \"1\"\n2) \"1\"",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "csharp",
      "code": "var rides = db.HashIncrement(\"bike:1\", \"rides\");\n        Console.WriteLine($\"Rides: {rides}\");\n        // Rides: 1\n\n        rides = db.HashIncrement(\"bike:1\", \"rides\");\n        Console.WriteLine($\"Rides: {rides}\");\n        // Rides: 2\n\n        rides = db.HashIncrement(\"bike:1\", \"rides\");\n        Console.WriteLine($\"Rides: {rides}\");\n        // Rides: 3\n\n        var crashes = db.HashIncrement(\"bike:1\", \"crashes\");\n        Console.WriteLine($\"Crashes: {crashes}\");\n        // Crashes: 1\n\n        var owners = db.HashIncrement(\"bike:1\", \"owners\");\n        Console.WriteLine($\"Owners: {owners}\");\n        // Owners: 1\n\n        var stats = db.HashGet(\"bike:1\", [\"crashes\", \"owners\"]);\n        Console.WriteLine($\"Bike stats: crashes={stats[0]}, owners={stats[1]}\");\n        // Bike stats: crashes=1, owners=1",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "go",
      "code": "res8, err := rdb.HIncrBy(ctx, \"bike:1:stats\", \"rides\", 1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res8) // >>> 1\n\n\tres9, err := rdb.HIncrBy(ctx, \"bike:1:stats\", \"rides\", 1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res9) // >>> 2\n\n\tres10, err := rdb.HIncrBy(ctx, \"bike:1:stats\", \"rides\", 1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res10) // >>> 3\n\n\tres11, err := rdb.HIncrBy(ctx, \"bike:1:stats\", \"crashes\", 1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res11) // >>> 1\n\n\tres12, err := rdb.HIncrBy(ctx, \"bike:1:stats\", \"owners\", 1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res12) // >>> 1\n\n\tres13, err := rdb.HGet(ctx, \"bike:1:stats\", \"rides\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res13) // >>> 3\n\n\tres14, err := rdb.HMGet(ctx, \"bike:1:stats\", \"crashes\", \"owners\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res14) // >>> [1 1]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "java",
      "code": "CompletableFuture<Void> incrByGetMget = asyncCommands.hincrby(\"bike:1:stats\", \"rides\", 1).thenCompose(res7 -> {\n                System.out.println(res7); // >>> 1\n                return asyncCommands.hincrby(\"bike:1:stats\", \"rides\", 1);\n            }).thenCompose(res8 -> {\n                System.out.println(res8); // >>> 2\n                return asyncCommands.hincrby(\"bike:1:stats\", \"rides\", 1);\n            }).thenCompose(res9 -> {\n                System.out.println(res9); // >>> 3\n                return asyncCommands.hincrby(\"bike:1:stats\", \"crashes\", 1);\n            }).thenCompose(res10 -> {\n                System.out.println(res10); // >>> 1\n                return asyncCommands.hincrby(\"bike:1:stats\", \"owners\", 1);\n            }).thenCompose(res11 -> {\n                System.out.println(res11); // >>> 1\n                return asyncCommands.hget(\"bike:1:stats\", \"rides\");\n            }).thenCompose(res12 -> {\n                System.out.println(res12); // >>> 3\n                return asyncCommands.hmget(\"bike:1:stats\", \"crashes\", \"owners\");\n            })\n                    .thenAccept(System.out::println)\n                    // >>> [KeyValue[crashes, 1], KeyValue[owners, 1]]\n                    .toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "Mono<Void> incrByGetMget = reactiveCommands.hincrby(\"bike:1:stats\", \"rides\", 1).doOnNext(result -> {\n                System.out.println(result); // >>> 1\n            }).flatMap(v -> reactiveCommands.hincrby(\"bike:1:stats\", \"rides\", 1)).doOnNext(result -> {\n                System.out.println(result); // >>> 2\n            }).flatMap(v -> reactiveCommands.hincrby(\"bike:1:stats\", \"rides\", 1)).doOnNext(result -> {\n                System.out.println(result); // >>> 3\n            }).flatMap(v -> reactiveCommands.hincrby(\"bike:1:stats\", \"crashes\", 1)).doOnNext(result -> {\n                System.out.println(result); // >>> 1\n            }).flatMap(v -> reactiveCommands.hincrby(\"bike:1:stats\", \"owners\", 1)).doOnNext(result -> {\n                System.out.println(result); // >>> 1\n            }).then();\n\n            incrByGetMget.block();\n\n            Mono<String> getRides = reactiveCommands.hget(\"bike:1:stats\", \"rides\").doOnNext(result -> {\n                System.out.println(result); // >>> 3\n            });\n\n            Mono<List<KeyValue<String, String>>> getCrashesOwners = reactiveCommands.hmget(\"bike:1:stats\", \"crashes\", \"owners\")\n                    .collectList().doOnNext(result -> {\n                        System.out.println(result);\n                        // >>> [KeyValue[crashes, 1], KeyValue[owners, 1]]\n                    });",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "Long res8 = jedis.hincrBy(\"bike:1:stats\", \"rides\", 1);\n      System.out.println(res8); // 1\n      Long res9 = jedis.hincrBy(\"bike:1:stats\", \"rides\", 1);\n      System.out.println(res9); // 2\n      Long res10 = jedis.hincrBy(\"bike:1:stats\", \"rides\", 1);\n      System.out.println(res10); // 3\n      Long res11 = jedis.hincrBy(\"bike:1:stats\", \"crashes\", 1);\n      System.out.println(res11); // 1\n      Long res12 = jedis.hincrBy(\"bike:1:stats\", \"owners\", 1);\n      System.out.println(res12); // 1\n      String res13 = jedis.hget(\"bike:1:stats\", \"rides\");\n      System.out.println(res13); // 3\n      List<String> res14 = jedis.hmget(\"bike:1:stats\", \"crashes\", \"owners\");\n      System.out.println(res14); // [1, 1]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "javascript",
      "code": "const res11 = await client.hIncrBy('bike:1:stats', 'rides', 1)\nconsole.log(res11)  // 1\nconst res12 = await client.hIncrBy('bike:1:stats', 'rides', 1)\nconsole.log(res12)  // 2\nconst res13 = await client.hIncrBy('bike:1:stats', 'rides', 1)\nconsole.log(res13)  // 3\nconst res14 = await client.hIncrBy('bike:1:stats', 'crashes', 1)\nconsole.log(res14)  // 1\nconst res15 = await client.hIncrBy('bike:1:stats', 'owners', 1)\nconsole.log(res15)  // 1\nconst res16 = await client.hGet('bike:1:stats', 'rides')\nconsole.log(res16)  // 3\nconst res17 = await client.hmGet('bike:1:stats', ['crashes', 'owners'])\nconsole.log(res17)  // ['1', '1']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "php",
      "code": "$res8 = $r->hincrby('bike:1:stats', 'rides', 1);\n        echo $res8 . PHP_EOL;\n        // >>> 1\n\n        $res9 = $r->hincrby('bike:1:stats', 'rides', 1);\n        echo $res9 . PHP_EOL;\n        // >>> 2\n\n        $res10 = $r->hincrby('bike:1:stats', 'rides', 1);\n        echo $res10 . PHP_EOL;\n        // >>> 3\n\n        $res11 = $r->hincrby('bike:1:stats', 'crashes', 1);\n        echo $res11 . PHP_EOL;\n        // >>> 1\n\n        $res12 = $r->hincrby('bike:1:stats', 'owners', 1);\n        echo $res12 . PHP_EOL;\n        // >>> 1\n\n        $res13 = $r->hget('bike:1:stats', 'rides');\n        echo $res13 . PHP_EOL;\n        // >>> 3\n\n        $res14 = $r->hmget('bike:1:stats', ['crashes', 'owners']);\n        echo json_encode($res14) . PHP_EOL;\n        // >>> [\"1\",\"1\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "python",
      "code": "res11 = r.hincrby(\"bike:1:stats\", \"rides\", 1)\nprint(res11)\n# >>> 1\nres12 = r.hincrby(\"bike:1:stats\", \"rides\", 1)\nprint(res12)\n# >>> 2\nres13 = r.hincrby(\"bike:1:stats\", \"rides\", 1)\nprint(res13)\n# >>> 3\nres14 = r.hincrby(\"bike:1:stats\", \"crashes\", 1)\nprint(res14)\n# >>> 1\nres15 = r.hincrby(\"bike:1:stats\", \"owners\", 1)\nprint(res15)\n# >>> 1\nres16 = r.hget(\"bike:1:stats\", \"rides\")\nprint(res16)\n# >>> 3\nres17 = r.hmget(\"bike:1:stats\", [\"crashes\", \"owners\"])\nprint(res17)\n# >>> ['1', '1']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "ruby",
      "code": "res8 = r.hincrby('bike:1:stats', 'rides', 1)\nputs res8 # >>> 1\n\nres9 = r.hincrby('bike:1:stats', 'rides', 1)\nputs res9 # >>> 2\n\nres10 = r.hincrby('bike:1:stats', 'rides', 1)\nputs res10 # >>> 3\n\nres11 = r.hincrby('bike:1:stats', 'crashes', 1)\nputs res11 # >>> 1\n\nres12 = r.hincrby('bike:1:stats', 'owners', 1)\nputs res12 # >>> 1\n\nres13 = r.hget('bike:1:stats', 'rides')\nputs res13 # >>> 3\n\nres14 = r.hmget('bike:1:stats', 'owners', 'crashes')\nputs res14.inspect # >>> [\"1\", \"1\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "rust",
      "code": "if let Ok(res) = r.hincr(\"bike:1:stats\", \"rides\", 1).await {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 1\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1:stats\", \"rides\", 1).await {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 2\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1:stats\", \"rides\", 1).await {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 3\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1:stats\", \"crashes\", 1).await {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 1\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1:stats\", \"owners\", 1).await {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 1\n        }\n\n        match r.hget(\"bike:1:stats\", \"rides\").await {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");   // >>> 3\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1:stats rides: {e}\");\n                return;\n            }\n        };\n\n        match r.hmget(\"bike:1:stats\", &[\"crashes\", \"owners\"]).await {\n            Ok(res) => {\n                let res: Vec<i32> = res;\n                println!(\"{res:?}\");   // >>> [1, 1]\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1:stats crashes and owners: {e}\");\n                return;\n            }\n        };",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "rust",
      "code": "if let Ok(res) = r.hincr(\"bike:1:stats\", \"rides\", 1) {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 1\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1:stats\", \"rides\", 1) {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 2\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1:stats\", \"rides\", 1) {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 3\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1:stats\", \"crashes\", 1) {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 1\n        }\n\n        if let Ok(res) = r.hincr(\"bike:1:stats\", \"owners\", 1) {\n            let res: i32 = res;\n            println!(\"{res}\");    // >>> 1\n        }\n\n        match r.hget(\"bike:1:stats\", \"rides\") {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");   // >>> 3\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1:stats rides: {e}\");\n                return;\n            }\n        };\n\n        match r.hmget(\"bike:1:stats\", &[\"crashes\", \"owners\"]) {\n            Ok(res) => {\n                let res: Vec<i32> = res;\n                println!(\"{res:?}\");   // >>> [1, 1]\n            },\n            Err(e) => {\n                println!(\"Error getting bike:1:stats crashes and owners: {e}\");\n                return;\n            }\n        };",
      "section_id": "examples"
    },
    {
      "id": "field-expiration-examples-ex0",
      "language": "plaintext",
      "code": "> DEL sensor:sensor1\n(integer) 0\n> HSET sensor:sensor1 air_quality 256 battery_level 89\n(integer) 2\n> HEXPIRE sensor:sensor1 60 FIELDS 2 air_quality battery_level\n1) (integer) 1\n2) (integer) 1\n> HTTL sensor:sensor1 FIELDS 2 air_quality battery_level\n1) (integer) 60\n2) (integer) 60",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex1",
      "language": "csharp",
      "code": "db.KeyDelete(\"sensor:sensor1\");\n        db.HashSet(\"sensor:sensor1\", [\n            new(\"air_quality\", 256),\n            new(\"battery_level\", 89)\n        ]);\n\n        // Set a TTL of 60 seconds on two fields of the hash.\n        ExpireResult[] hexpireResult = db.HashFieldExpire(\n            \"sensor:sensor1\",\n            new RedisValue[] { \"air_quality\", \"battery_level\" },\n            TimeSpan.FromSeconds(60)\n        );\n        Console.WriteLine(string.Join(\", \", hexpireResult));\n        // Success, Success\n\n        // Retrieve the remaining TTL for those fields.\n        long[] httlResult = db.HashFieldGetTimeToLive(\n            \"sensor:sensor1\",\n            new RedisValue[] { \"air_quality\", \"battery_level\" }\n        );\n        Console.WriteLine(httlResult.Length);\n        // 2",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex2",
      "language": "go",
      "code": "rdb.Del(ctx, \"sensor:sensor1\")\n\trdb.HSet(ctx, \"sensor:sensor1\", \"air_quality\", 256, \"battery_level\", 89)\n\n\t// Set a TTL of 60 seconds on two fields of the hash.\n\tres18, err := rdb.HExpire(ctx, \"sensor:sensor1\", 60*time.Second,\n\t\t\"air_quality\", \"battery_level\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res18) // >>> [1 1]\n\n\t// Retrieve the remaining TTL for those fields (returns one value per field).\n\tres19, err := rdb.HTTL(ctx, \"sensor:sensor1\", \"air_quality\", \"battery_level\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(len(res19)) // >>> 2",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex3",
      "language": "java",
      "code": "Map<String, String> sensor1 = new HashMap<>();\n            sensor1.put(\"air_quality\", \"256\");\n            sensor1.put(\"battery_level\", \"89\");\n\n            CompletableFuture<Void> hExpire = asyncCommands.del(\"sensor:sensor1\")\n                    .thenCompose(delRes -> asyncCommands.hset(\"sensor:sensor1\", sensor1))\n                    // Set a TTL of 60 seconds on two fields of the hash.\n                    .thenCompose(hsetRes -> asyncCommands.hexpire(\"sensor:sensor1\", 60, \"air_quality\", \"battery_level\"))\n                    .thenCompose(res15 -> {\n                        System.out.println(res15); // >>> [1, 1]\n                        // Retrieve the remaining TTL for those fields.\n                        return asyncCommands.httl(\"sensor:sensor1\", \"air_quality\", \"battery_level\");\n                    })\n                    .thenAccept(res16 -> System.out.println(res16.size()))\n                    // >>> 2\n                    .toCompletableFuture();",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex4",
      "language": "java",
      "code": "Map<String, String> sensor1 = new HashMap<>();\n            sensor1.put(\"air_quality\", \"256\");\n            sensor1.put(\"battery_level\", \"89\");\n\n            // Set a TTL of 60 seconds on two fields of the hash.\n            Mono<List<Long>> hExpire = reactiveCommands.del(\"sensor:sensor1\")\n                    .then(reactiveCommands.hset(\"sensor:sensor1\", sensor1))\n                    .then(reactiveCommands.hexpire(\"sensor:sensor1\", 60, \"air_quality\", \"battery_level\").collectList())\n                    .doOnNext(result -> {\n                        System.out.println(result);\n                        // >>> [1, 1]\n                    });\n\n            hExpire.block();\n\n            // Retrieve the remaining TTL for those fields.\n            Mono<List<Long>> hTtl = reactiveCommands.httl(\"sensor:sensor1\", \"air_quality\", \"battery_level\")\n                    .collectList().doOnNext(result -> {\n                        System.out.println(result.size());\n                        // >>> 2\n                    });\n\n            hTtl.block();",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex5",
      "language": "java",
      "code": "jedis.del(\"sensor:sensor1\");\n      Map<String, String> sensor1 = new HashMap<>();\n      sensor1.put(\"air_quality\", \"256\");\n      sensor1.put(\"battery_level\", \"89\");\n      jedis.hset(\"sensor:sensor1\", sensor1);\n\n      // Set a TTL of 60 seconds on two fields of the hash.\n      List<Long> res15 = jedis.hexpire(\"sensor:sensor1\", 60, \"air_quality\", \"battery_level\");\n      System.out.println(res15); // [1, 1]\n\n      // Retrieve the remaining TTL for those fields.\n      List<Long> res16 = jedis.httl(\"sensor:sensor1\", \"air_quality\", \"battery_level\");\n      System.out.println(res16.size()); // 2",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex6",
      "language": "javascript",
      "code": "await client.del('sensor:sensor1')\nawait client.hSet('sensor:sensor1', { 'air_quality': 256, 'battery_level': 89 })\n\n// Set a TTL of 60 seconds on two fields of the hash.\nconst res18 = await client.hExpire('sensor:sensor1', ['air_quality', 'battery_level'], 60)\nconsole.log(res18)  // [1, 1]\n\n// Retrieve the remaining TTL for those fields.\nconst res19 = await client.hTTL('sensor:sensor1', ['air_quality', 'battery_level'])\nconsole.log(res19)  // [60, 60] (or close to 60)",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex7",
      "language": "php",
      "code": "$r->del('sensor:sensor1');\n        $r->hmset('sensor:sensor1', [\n            'air_quality' => 256,\n            'battery_level' => 89,\n        ]);\n\n        // Set a TTL of 60 seconds on two fields of the hash.\n        $res15 = $r->hexpire('sensor:sensor1', 60, ['air_quality', 'battery_level']);\n        echo json_encode($res15) . PHP_EOL;\n        // >>> [1,1]\n\n        // Retrieve the remaining TTL for those fields.\n        $res16 = $r->httl('sensor:sensor1', ['air_quality', 'battery_level']);\n        echo count($res16) . PHP_EOL;\n        // >>> 2",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex8",
      "language": "python",
      "code": "r.delete(\"sensor:sensor1\")\nr.hset(\"sensor:sensor1\", mapping={\"air_quality\": 256, \"battery_level\": 89})\n\n# Set a TTL of 60 seconds on two fields of the hash.\nres18 = r.hexpire(\"sensor:sensor1\", 60, \"air_quality\", \"battery_level\")\nprint(res18)\n# >>> [1, 1]\n\n# Retrieve the remaining TTL for those fields.\nres19 = r.httl(\"sensor:sensor1\", \"air_quality\", \"battery_level\")\nprint(res19)\n# >>> [60, 60]\n# (your actual values may be slightly lower)",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex9",
      "language": "ruby",
      "code": "r.del('sensor:sensor1')\nr.hset('sensor:sensor1', { 'air_quality' => 256, 'battery_level' => 89 })\n\n# Set a TTL of 60 seconds on two fields of the hash.\nres15 = r.hexpire('sensor:sensor1', 60, 'air_quality', 'battery_level')\nputs res15.inspect # >>> [1, 1]\n\n# Retrieve the remaining TTL for those fields.\nres16 = r.httl('sensor:sensor1', 'air_quality', 'battery_level')\nputs res16.inspect # >>> [60, 60]\n# (your actual values may be slightly lower)",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex10",
      "language": "rust",
      "code": "let _: () = r.del(\"sensor:sensor1\").await.expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"sensor:sensor1\",\n            &[(\"air_quality\", \"256\"), (\"battery_level\", \"89\")],\n        ).await.expect(\"Failed to hset\");\n\n        // Set a TTL of 60 seconds on two fields of the hash.\n        match r.hexpire(\"sensor:sensor1\", 60, redis::ExpireOption::NONE, &[\"air_quality\", \"battery_level\"]).await {\n            Ok(res18) => {\n                let res18: Vec<i64> = res18;\n                println!(\"{:?}\", res18);    // >>> [1, 1]\n            },\n            Err(e) => {\n                println!(\"Error setting expiration: {e}\");\n                return;\n            }\n        }\n\n        // Retrieve the remaining TTL for those fields.\n        match r.httl(\"sensor:sensor1\", &[\"air_quality\", \"battery_level\"]).await {\n            Ok(res19) => {\n                let res19: Vec<i64> = res19;\n                println!(\"{}\", res19.len());    // >>> 2\n            },\n            Err(e) => {\n                println!(\"Error getting TTL: {e}\");\n                return;\n            }\n        }",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex11",
      "language": "rust",
      "code": "let _: () = r.del(\"sensor:sensor1\").expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"sensor:sensor1\",\n            &[(\"air_quality\", \"256\"), (\"battery_level\", \"89\")],\n        ).expect(\"Failed to hset\");\n\n        // Set a TTL of 60 seconds on two fields of the hash.\n        match r.hexpire(\"sensor:sensor1\", 60, redis::ExpireOption::NONE, &[\"air_quality\", \"battery_level\"]) {\n            Ok(res18) => {\n                let res18: Vec<i64> = res18;\n                println!(\"{:?}\", res18);    // >>> [1, 1]\n            },\n            Err(e) => {\n                println!(\"Error setting expiration: {e}\");\n                return;\n            }\n        }\n\n        // Retrieve the remaining TTL for those fields.\n        match r.httl(\"sensor:sensor1\", &[\"air_quality\", \"battery_level\"]) {\n            Ok(res19) => {\n                let res19: Vec<i64> = res19;\n                println!(\"{}\", res19.len());    // >>> 2\n            },\n            Err(e) => {\n                println!(\"Error getting TTL: {e}\");\n                return;\n            }\n        }",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex12",
      "language": "plaintext",
      "code": "> DEL sensor:sensor1\n(integer) 1\n> HSET sensor:sensor1 air_quality 256 battery_level 89\n(integer) 2\n> HPEXPIRE sensor:sensor1 60000 FIELDS 1 air_quality\n1) (integer) 1\n> HPTTL sensor:sensor1 FIELDS 1 air_quality\n1) (integer) 59994",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex13",
      "language": "csharp",
      "code": "db.KeyDelete(\"sensor:sensor1\");\n        db.HashSet(\"sensor:sensor1\", [\n            new(\"air_quality\", 256),\n            new(\"battery_level\", 89)\n        ]);\n\n        // Set the TTL of the 'air_quality' field, expressed in milliseconds.\n        ExpireResult[] hpexpireResult = db.HashFieldExpire(\n            \"sensor:sensor1\",\n            new RedisValue[] { \"air_quality\" },\n            TimeSpan.FromMilliseconds(60000)\n        );\n        Console.WriteLine(string.Join(\", \", hpexpireResult));\n        // Success\n\n        // Retrieve the remaining TTL.\n        long[] hpttlResult = db.HashFieldGetTimeToLive(\n            \"sensor:sensor1\",\n            new RedisValue[] { \"air_quality\" }\n        );\n        Console.WriteLine(hpttlResult.Length);\n        // 1",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex14",
      "language": "go",
      "code": "rdb.Del(ctx, \"sensor:sensor1\")\n\trdb.HSet(ctx, \"sensor:sensor1\", \"air_quality\", 256, \"battery_level\", 89)\n\n\t// Set the TTL of the 'air_quality' field in milliseconds.\n\tres20, err := rdb.HPExpire(ctx, \"sensor:sensor1\", 60000*time.Millisecond,\n\t\t\"air_quality\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res20) // >>> [1]\n\n\t// Retrieve the remaining TTL in milliseconds (returns one value per field).\n\tres21, err := rdb.HPTTL(ctx, \"sensor:sensor1\", \"air_quality\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(len(res21)) // >>> 1",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex15",
      "language": "java",
      "code": "CompletableFuture<Void> hpExpire = hExpire\n                    .thenCompose(prev -> asyncCommands.del(\"sensor:sensor1\"))\n                    .thenCompose(delRes -> asyncCommands.hset(\"sensor:sensor1\", sensor1))\n                    // Set the TTL of the 'air_quality' field in milliseconds.\n                    .thenCompose(hsetRes -> asyncCommands.hpexpire(\"sensor:sensor1\", 60000, \"air_quality\"))\n                    .thenCompose(res17 -> {\n                        System.out.println(res17); // >>> [1]\n                        // Retrieve the remaining TTL in milliseconds.\n                        return asyncCommands.hpttl(\"sensor:sensor1\", \"air_quality\");\n                    })\n                    .thenAccept(res18 -> System.out.println(res18.size()))\n                    // >>> 1\n                    .toCompletableFuture();",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex16",
      "language": "java",
      "code": "// Set the TTL of the 'air_quality' field in milliseconds.\n            Mono<List<Long>> hpExpire = reactiveCommands.del(\"sensor:sensor1\")\n                    .then(reactiveCommands.hset(\"sensor:sensor1\", sensor1))\n                    .then(reactiveCommands.hpexpire(\"sensor:sensor1\", 60000, \"air_quality\").collectList())\n                    .doOnNext(result -> {\n                        System.out.println(result);\n                        // >>> [1]\n                    });\n\n            hpExpire.block();\n\n            // Retrieve the remaining TTL in milliseconds.\n            Mono<List<Long>> hpTtl = reactiveCommands.hpttl(\"sensor:sensor1\", \"air_quality\")\n                    .collectList().doOnNext(result -> {\n                        System.out.println(result.size());\n                        // >>> 1\n                    });\n\n            hpTtl.block();",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex17",
      "language": "java",
      "code": "jedis.del(\"sensor:sensor1\");\n      jedis.hset(\"sensor:sensor1\", sensor1);\n\n      // Set the TTL of the 'air_quality' field in milliseconds.\n      List<Long> res17 = jedis.hpexpire(\"sensor:sensor1\", 60000, \"air_quality\");\n      System.out.println(res17); // [1]\n\n      // Retrieve the remaining TTL in milliseconds.\n      List<Long> res18 = jedis.hpttl(\"sensor:sensor1\", \"air_quality\");\n      System.out.println(res18.size()); // 1",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex18",
      "language": "javascript",
      "code": "await client.del('sensor:sensor1')\nawait client.hSet('sensor:sensor1', { 'air_quality': 256, 'battery_level': 89 })\n\n// Set the TTL of the 'air_quality' field in milliseconds.\nconst res20 = await client.hpExpire('sensor:sensor1', ['air_quality'], 60000)\nconsole.log(res20)  // [1]\n\n// Retrieve the remaining TTL in milliseconds.\nconst res21 = await client.hpTTL('sensor:sensor1', ['air_quality'])\nconsole.log(res21)  // [59994] (your actual value may vary)",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex19",
      "language": "php",
      "code": "$r->del('sensor:sensor1');\n        $r->hmset('sensor:sensor1', [\n            'air_quality' => 256,\n            'battery_level' => 89,\n        ]);\n\n        // Set the TTL of the 'air_quality' field in milliseconds.\n        $res17 = $r->hpexpire('sensor:sensor1', 60000, ['air_quality']);\n        echo json_encode($res17) . PHP_EOL;\n        // >>> [1]\n\n        // Retrieve the remaining TTL in milliseconds.\n        $res18 = $r->hpttl('sensor:sensor1', ['air_quality']);\n        echo count($res18) . PHP_EOL;\n        // >>> 1",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex20",
      "language": "python",
      "code": "r.delete(\"sensor:sensor1\")\nr.hset(\"sensor:sensor1\", mapping={\"air_quality\": 256, \"battery_level\": 89})\n\n# Set the TTL of the 'air_quality' field in milliseconds.\nres20 = r.hpexpire(\"sensor:sensor1\", 60000, \"air_quality\")\nprint(res20)\n# >>> [1]\n\n# Retrieve the remaining TTL in milliseconds.\nres21 = r.hpttl(\"sensor:sensor1\", \"air_quality\")\nprint(res21)\n# >>> [59994]\n# (your actual value may vary)",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex21",
      "language": "ruby",
      "code": "r.del('sensor:sensor1')\nr.hset('sensor:sensor1', { 'air_quality' => 256, 'battery_level' => 89 })\n\n# Set the TTL of the 'air_quality' field in milliseconds.\nres17 = r.hpexpire('sensor:sensor1', 60_000, 'air_quality')\nputs res17.inspect # >>> [1]\n\n# Retrieve the remaining TTL in milliseconds.\nres18 = r.hpttl('sensor:sensor1', 'air_quality')\nputs res18.inspect # >>> [59999]\n# (your actual value may vary)",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex22",
      "language": "rust",
      "code": "let _: () = r.del(\"sensor:sensor1\").await.expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"sensor:sensor1\",\n            &[(\"air_quality\", \"256\"), (\"battery_level\", \"89\")],\n        ).await.expect(\"Failed to hset\");\n\n        // Set the TTL of the 'air_quality' field in milliseconds.\n        match r.hpexpire(\"sensor:sensor1\", 60000, redis::ExpireOption::NONE, &[\"air_quality\"]).await {\n            Ok(res20) => {\n                let res20: Vec<i64> = res20;\n                println!(\"{:?}\", res20);    // >>> [1]\n            },\n            Err(e) => {\n                println!(\"Error setting expiration: {e}\");\n                return;\n            }\n        }\n\n        // Retrieve the remaining TTL in milliseconds.\n        match r.hpttl(\"sensor:sensor1\", &[\"air_quality\"]).await {\n            Ok(res21) => {\n                let res21: Vec<i64> = res21;\n                println!(\"{}\", res21.len());    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error getting PTTL: {e}\");\n                return;\n            }\n        }",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex23",
      "language": "rust",
      "code": "let _: () = r.del(\"sensor:sensor1\").expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"sensor:sensor1\",\n            &[(\"air_quality\", \"256\"), (\"battery_level\", \"89\")],\n        ).expect(\"Failed to hset\");\n\n        // Set the TTL of the 'air_quality' field in milliseconds.\n        match r.hpexpire(\"sensor:sensor1\", 60000, redis::ExpireOption::NONE, &[\"air_quality\"]) {\n            Ok(res20) => {\n                let res20: Vec<i64> = res20;\n                println!(\"{:?}\", res20);    // >>> [1]\n            },\n            Err(e) => {\n                println!(\"Error setting expiration: {e}\");\n                return;\n            }\n        }\n\n        // Retrieve the remaining TTL in milliseconds.\n        match r.hpttl(\"sensor:sensor1\", &[\"air_quality\"]) {\n            Ok(res21) => {\n                let res21: Vec<i64> = res21;\n                println!(\"{}\", res21.len());    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error getting PTTL: {e}\");\n                return;\n            }\n        }",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex24",
      "language": "plaintext",
      "code": "> DEL sensor:sensor1\n(integer) 1\n> HSET sensor:sensor1 air_quality 256 battery_level 89\n(integer) 2\n# Set the expiration to a Unix time in the future\n# (4102444800 is just an example; use a timestamp appropriate for your use case).\n> HEXPIREAT sensor:sensor1 4102444800 FIELDS 1 air_quality\n1) (integer) 1\n> HEXPIRETIME sensor:sensor1 FIELDS 1 air_quality\n1) (integer) 4102444800",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex25",
      "language": "csharp",
      "code": "db.KeyDelete(\"sensor:sensor1\");\n        db.HashSet(\"sensor:sensor1\", [\n            new(\"air_quality\", 256),\n            new(\"battery_level\", 89)\n        ]);\n\n        // Set the expiration of 'air_quality' to a time 24 hours from now.\n        ExpireResult[] hexpireAtResult = db.HashFieldExpire(\n            \"sensor:sensor1\",\n            new RedisValue[] { \"air_quality\" },\n            DateTime.UtcNow.AddHours(24)\n        );\n        Console.WriteLine(string.Join(\", \", hexpireAtResult));\n        // Success\n\n        // Retrieve the expiration time as a Unix timestamp.\n        long[] hexpireTimeResult = db.HashFieldGetExpireDateTime(\n            \"sensor:sensor1\",\n            new RedisValue[] { \"air_quality\" }\n        );\n        Console.WriteLine(hexpireTimeResult.Length);\n        // 1",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex26",
      "language": "go",
      "code": "rdb.Del(ctx, \"sensor:sensor1\")\n\trdb.HSet(ctx, \"sensor:sensor1\", \"air_quality\", 256, \"battery_level\", 89)\n\n\t// Set the expiration of 'air_quality' to a time 24 hours from now.\n\tres22, err := rdb.HExpireAt(ctx, \"sensor:sensor1\", time.Now().Add(24*time.Hour),\n\t\t\"air_quality\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(res22) // >>> [1]\n\n\t// Retrieve the expiration time as a Unix timestamp (returns one value per field).\n\tres23, err := rdb.HExpireTime(ctx, \"sensor:sensor1\", \"air_quality\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(len(res23)) // >>> 1",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex27",
      "language": "java",
      "code": "long expireAtSeconds = System.currentTimeMillis() / 1000L + 24 * 60 * 60;\n            CompletableFuture<Void> hExpireAt = hpExpire\n                    .thenCompose(prev -> asyncCommands.del(\"sensor:sensor1\"))\n                    .thenCompose(delRes -> asyncCommands.hset(\"sensor:sensor1\", sensor1))\n                    // Set the expiration of 'air_quality' to a Unix time 24 hours from now.\n                    .thenCompose(hsetRes -> asyncCommands.hexpireat(\"sensor:sensor1\", expireAtSeconds, \"air_quality\"))\n                    .thenCompose(res19 -> {\n                        System.out.println(res19); // >>> [1]\n                        // Retrieve the expiration time as a Unix timestamp in seconds.\n                        return asyncCommands.hexpiretime(\"sensor:sensor1\", \"air_quality\");\n                    })\n                    .thenAccept(res20 -> System.out.println(res20.size()))\n                    // >>> 1\n                    .toCompletableFuture();",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex28",
      "language": "java",
      "code": "long expireAtSeconds = System.currentTimeMillis() / 1000L + 24 * 60 * 60;\n\n            // Set the expiration of 'air_quality' to a Unix time 24 hours from now.\n            Mono<List<Long>> hExpireAt = reactiveCommands.del(\"sensor:sensor1\")\n                    .then(reactiveCommands.hset(\"sensor:sensor1\", sensor1))\n                    .then(reactiveCommands.hexpireat(\"sensor:sensor1\", expireAtSeconds, \"air_quality\").collectList())\n                    .doOnNext(result -> {\n                        System.out.println(result);\n                        // >>> [1]\n                    });\n\n            hExpireAt.block();\n\n            // Retrieve the expiration time as a Unix timestamp in seconds.\n            Mono<List<Long>> hExpireTime = reactiveCommands.hexpiretime(\"sensor:sensor1\", \"air_quality\")\n                    .collectList().doOnNext(result -> {\n                        System.out.println(result.size());\n                        // >>> 1\n                    });\n\n            hExpireTime.block();",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex29",
      "language": "java",
      "code": "jedis.del(\"sensor:sensor1\");\n      jedis.hset(\"sensor:sensor1\", sensor1);\n\n      // Set the expiration of 'air_quality' to a Unix time 24 hours from now.\n      long expireAt = System.currentTimeMillis() / 1000L + 24 * 60 * 60;\n      List<Long> res19 = jedis.hexpireAt(\"sensor:sensor1\", expireAt, \"air_quality\");\n      System.out.println(res19); // [1]\n\n      // Retrieve the expiration time as a Unix timestamp in seconds.\n      List<Long> res20 = jedis.hexpireTime(\"sensor:sensor1\", \"air_quality\");\n      System.out.println(res20.size()); // 1",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex30",
      "language": "javascript",
      "code": "await client.del('sensor:sensor1')\nawait client.hSet('sensor:sensor1', { 'air_quality': 256, 'battery_level': 89 })\n\n// Set the expiration of 'air_quality' to a Unix time 24 hours from now.\nconst expireAt = Math.floor(Date.now() / 1000) + 24 * 60 * 60\nconst res22 = await client.hExpireAt('sensor:sensor1', ['air_quality'], expireAt)\nconsole.log(res22)  // [1]\n\n// Retrieve the expiration time as a Unix timestamp in seconds.\nconst res23 = await client.hExpireTime('sensor:sensor1', ['air_quality'])\nconsole.log(res23)  // [1717668041] (your actual value will vary)",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex31",
      "language": "php",
      "code": "$r->del('sensor:sensor1');\n        $r->hmset('sensor:sensor1', [\n            'air_quality' => 256,\n            'battery_level' => 89,\n        ]);\n\n        // Set the expiration of 'air_quality' to a Unix time 24 hours from now.\n        $res19 = $r->hexpireat('sensor:sensor1', time() + 24 * 60 * 60, ['air_quality']);\n        echo json_encode($res19) . PHP_EOL;\n        // >>> [1]\n\n        // Retrieve the expiration time as a Unix timestamp in seconds.\n        $res20 = $r->hexpiretime('sensor:sensor1', ['air_quality']);\n        echo count($res20) . PHP_EOL;\n        // >>> 1",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex32",
      "language": "python",
      "code": "r.delete(\"sensor:sensor1\")\nr.hset(\"sensor:sensor1\", mapping={\"air_quality\": 256, \"battery_level\": 89})\n\n# Set the expiration of 'air_quality' to a Unix time 24 hours from now.\nres22 = r.hexpireat(\n    \"sensor:sensor1\",\n    int(time.time()) + 24 * 60 * 60,\n    \"air_quality\",\n)\nprint(res22)\n# >>> [1]\n\n# Retrieve the expiration time as a Unix timestamp in seconds.\nres23 = r.hexpiretime(\"sensor:sensor1\", \"air_quality\")\nprint(res23)\n# >>> [1717668041]\n# (your actual value will vary)",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex33",
      "language": "rust",
      "code": "let _: () = r.del(\"sensor:sensor1\").await.expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"sensor:sensor1\",\n            &[(\"air_quality\", \"256\"), (\"battery_level\", \"89\")],\n        ).await.expect(\"Failed to hset\");\n\n        // Set the expiration of 'air_quality' to a Unix time 24 hours from now.\n        let now = std::time::SystemTime::now()\n            .duration_since(std::time::UNIX_EPOCH)\n            .expect(\"Time went backwards\")\n            .as_secs() as i64;\n\n        match r.hexpire_at(\"sensor:sensor1\", now + 24 * 60 * 60, redis::ExpireOption::NONE, &[\"air_quality\"]).await {\n            Ok(res22) => {\n                let res22: Vec<i64> = res22;\n                println!(\"{:?}\", res22);    // >>> [1]\n            },\n            Err(e) => {\n                println!(\"Error setting expiration: {e}\");\n                return;\n            }\n        }\n\n        // Retrieve the expiration time as a Unix timestamp in seconds.\n        match r.hexpire_time(\"sensor:sensor1\", &[\"air_quality\"]).await {\n            Ok(res23) => {\n                let res23: Vec<i64> = res23;\n                println!(\"{}\", res23.len());    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error getting expiration time: {e}\");\n                return;\n            }\n        }",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "field-expiration-examples-ex34",
      "language": "rust",
      "code": "let _: () = r.del(\"sensor:sensor1\").expect(\"Failed to del\");\n        let _: () = r.hset_multiple(\n            \"sensor:sensor1\",\n            &[(\"air_quality\", \"256\"), (\"battery_level\", \"89\")],\n        ).expect(\"Failed to hset\");\n\n        // Set the expiration of 'air_quality' to a Unix time 24 hours from now.\n        let now = std::time::SystemTime::now()\n            .duration_since(std::time::UNIX_EPOCH)\n            .expect(\"Time went backwards\")\n            .as_secs() as i64;\n\n        match r.hexpire_at(\"sensor:sensor1\", now + 24 * 60 * 60, redis::ExpireOption::NONE, &[\"air_quality\"]) {\n            Ok(res22) => {\n                let res22: Vec<i64> = res22;\n                println!(\"{:?}\", res22);    // >>> [1]\n            },\n            Err(e) => {\n                println!(\"Error setting expiration: {e}\");\n                return;\n            }\n        }\n\n        // Retrieve the expiration time as a Unix timestamp in seconds.\n        match r.hexpire_time(\"sensor:sensor1\", &[\"air_quality\"]) {\n            Ok(res23) => {\n                let res23: Vec<i64> = res23;\n                println!(\"{}\", res23.len());    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error getting expiration time: {e}\");\n                return;\n            }\n        }",
      "section_id": "field-expiration-examples"
    },
    {
      "id": "bulk-import-with-himport-ex0",
      "language": "plaintext",
      "code": "> HIMPORT PREPARE user name email age\nOK\n> HIMPORT SET user:1 user Alice alice@example.com 34\nOK\n> HIMPORT SET user:2 user Bob bob@example.com 41\nOK\n> HIMPORT SET user:3 user Carol carol@example.com 29\nOK\n> HGETALL user:2\n1) \"age\"\n2) \"41\"\n3) \"name\"\n4) \"Bob\"\n5) \"email\"\n6) \"bob@example.com\"",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex1",
      "language": "csharp",
      "code": "// Declare the field names once.\n        await using var fields = HashImport.Create(\"name\", \"email\", \"age\");\n\n        // Create each hash by sending only its values.\n        await db.HashImportAsync(\"user:1\", fields, new RedisValue[] { \"Alice\", \"alice@example.com\", \"34\" });\n        await db.HashImportAsync(\"user:2\", fields, new RedisValue[] { \"Bob\", \"bob@example.com\", \"41\" });\n        await db.HashImportAsync(\"user:3\", fields, new RedisValue[] { \"Carol\", \"carol@example.com\", \"29\" });\n\n        // The result is an ordinary hash.\n        HashEntry[] res1 = await db.HashGetAllAsync(\"user:2\");\n        Console.WriteLine(string.Join(\", \", res1.Select(h => $\"{h.Name}: {h.Value}\")));\n        // >>> age: 41, name: Bob, email: bob@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex2",
      "language": "csharp",
      "code": "// Declare the field names once.\n        using var fields = HashImport.Create(\"name\", \"email\", \"age\");\n\n        // Create each hash by sending only its values.\n        db.HashImport(\"user:1\", fields, new RedisValue[] { \"Alice\", \"alice@example.com\", \"34\" });\n        db.HashImport(\"user:2\", fields, new RedisValue[] { \"Bob\", \"bob@example.com\", \"41\" });\n        db.HashImport(\"user:3\", fields, new RedisValue[] { \"Carol\", \"carol@example.com\", \"29\" });\n\n        // The result is an ordinary hash.\n        HashEntry[] res1 = db.HashGetAll(\"user:2\");\n        Console.WriteLine(string.Join(\", \", res1.Select(h => $\"{h.Name}: {h.Value}\")));\n        // >>> age: 41, name: Bob, email: bob@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex3",
      "language": "csharp",
      "code": "// Declare the field names once.\n        await using var fields = HashImport.Create(\"name\", \"email\", \"age\");\n\n        // Create each hash by sending only its values.\n        await db.HashImportAsync(\"user:1\", fields, new RedisValue[] { \"Alice\", \"alice@example.com\", \"34\" });\n        await db.HashImportAsync(\"user:2\", fields, new RedisValue[] { \"Bob\", \"bob@example.com\", \"41\" });\n        await db.HashImportAsync(\"user:3\", fields, new RedisValue[] { \"Carol\", \"carol@example.com\", \"29\" });\n\n        // The result is an ordinary hash.\n        HashEntry[] res1 = await db.HashGetAllAsync(\"user:2\");\n        Console.WriteLine(string.Join(\", \", res1.Select(h => $\"{h.Name}: {h.Value}\")));\n        // >>> age: 41, name: Bob, email: bob@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex4",
      "language": "csharp",
      "code": "// Declare the field names once.\n        using var fields = HashImport.Create(\"name\", \"email\", \"age\");\n\n        // Create each hash by sending only its values.\n        db.HashImport(\"user:1\", fields, new RedisValue[] { \"Alice\", \"alice@example.com\", \"34\" });\n        db.HashImport(\"user:2\", fields, new RedisValue[] { \"Bob\", \"bob@example.com\", \"41\" });\n        db.HashImport(\"user:3\", fields, new RedisValue[] { \"Carol\", \"carol@example.com\", \"29\" });\n\n        // The result is an ordinary hash.\n        HashEntry[] res1 = db.HashGetAll(\"user:2\");\n        Console.WriteLine(string.Join(\", \", res1.Select(h => $\"{h.Name}: {h.Value}\")));\n        // >>> age: 41, name: Bob, email: bob@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex5",
      "language": "go",
      "code": "// Declare the field names once.\n\tif err := rdb.HImportPrepare(ctx, \"user\", \"name\", \"email\", \"age\").Err(); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Create each hash by sending only its values.\n\tres1, err := rdb.HImportSet(ctx, \"user:1\", \"user\", \"Alice\", \"alice@example.com\", \"34\").Result()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(res1) // >>> OK\n\n\tif err := rdb.HImportSet(ctx, \"user:2\", \"user\", \"Bob\", \"bob@example.com\", \"41\").Err(); err != nil {\n\t\tpanic(err)\n\t}\n\tif err := rdb.HImportSet(ctx, \"user:3\", \"user\", \"Carol\", \"carol@example.com\", \"29\").Err(); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// The result is an ordinary hash.\n\tres2, err := rdb.HGetAll(ctx, \"user:2\").Result()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(res2) // >>> map[age:41 email:bob@example.com name:Bob]",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex6",
      "language": "java",
      "code": "// Declare the field names once.\n            try (HashImport<String> fieldset = HashImport.of(\"name\", \"email\", \"age\")) {\n                // Create each hash by sending only its values.\n                String res1 = syncCommands.himportSet(\"user:1\", fieldset, \"Alice\", \"alice@example.com\", \"34\");\n                System.out.println(res1); // >>> OK\n\n                syncCommands.himportSet(\"user:2\", fieldset, \"Bob\", \"bob@example.com\", \"41\");\n                syncCommands.himportSet(\"user:3\", fieldset, \"Carol\", \"carol@example.com\", \"29\");\n            }\n\n            // The result is an ordinary hash.\n            Map<String, String> res2 = syncCommands.hgetall(\"user:2\");\n            System.out.println(res2);\n            // >>> {age=41, name=Bob, email=bob@example.com}",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex7",
      "language": "java",
      "code": "CompletableFuture<Void> basicOps;\n\n            // Declare the field names once.\n            try (HashImport<String> fieldset = HashImport.of(\"name\", \"email\", \"age\")) {\n                // Create each hash by sending only its values.\n                RedisFuture<String> import1 = asyncCommands.himportSet(\n                        \"user:1\", fieldset, \"Alice\", \"alice@example.com\", \"34\");\n                asyncCommands.himportSet(\"user:2\", fieldset, \"Bob\", \"bob@example.com\", \"41\");\n                asyncCommands.himportSet(\"user:3\", fieldset, \"Carol\", \"carol@example.com\", \"29\");\n\n                basicOps = import1.thenCompose(res1 -> {\n                    System.out.println(res1); // >>> OK\n                    // The result is an ordinary hash.\n                    return asyncCommands.hgetall(\"user:2\");\n                }).thenAccept(res2 -> {\n                    System.out.println(res2);\n                    // >>> {age=41, name=Bob, email=bob@example.com}\n                }).toCompletableFuture();\n            }\n\n            basicOps.join();",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex8",
      "language": "java",
      "code": "// Declare the field names once.\n            try (HashImport<String> fieldset = HashImport.of(\"name\", \"email\", \"age\")) {\n                // Create each hash by sending only its values.\n                Mono<String> import1 = reactiveCommands\n                    .himportSet(\"user:1\", fieldset, \"Alice\", \"alice@example.com\", \"34\")\n                    .doOnNext(res1 -> {\n                        System.out.println(res1); // >>> OK\n                    });\n\n                Mono<String> import2 = reactiveCommands\n                    .himportSet(\"user:2\", fieldset, \"Bob\", \"bob@example.com\", \"41\");\n                Mono<String> import3 = reactiveCommands\n                    .himportSet(\"user:3\", fieldset, \"Carol\", \"carol@example.com\", \"29\");\n\n                // Subscribe before the fieldset closes.\n                Mono.when(import1, import2, import3).block();\n            }\n\n            // The result is an ordinary hash.\n            Mono<List<KeyValue<String, String>>> getAll = reactiveCommands.hgetall(\"user:2\")\n                .collectList()\n                .doOnNext(res2 -> {\n                    System.out.println(res2);\n                    // >>> [KeyValue[age, 41], KeyValue[name, Bob], KeyValue[email, bob@example.com]]\n                });\n\n            getAll.block();",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex9",
      "language": "java",
      "code": "// Declare the field names once.\n        try (HashImport fields = HashImport.of(\"name\", \"email\", \"age\")) {\n            // Create each hash by sending only its values.\n            String res1 = jedis.himportSet(\"user:1\", fields, \"Alice\", \"alice@example.com\", \"34\");\n            System.out.println(res1); // >>> OK\n\n            jedis.himportSet(\"user:2\", fields, \"Bob\", \"bob@example.com\", \"41\");\n            jedis.himportSet(\"user:3\", fields, \"Carol\", \"carol@example.com\", \"29\");\n        }\n\n        // The result is an ordinary hash.\n        Map<String, String> res2 = jedis.hgetAll(\"user:2\");\n        System.out.println(res2);\n        // >>> {name=Bob, age=41, email=bob@example.com}",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex10",
      "language": "javascript",
      "code": "// Declare the field names once.\nawait client.hImportPrepare('user', ['name', 'email', 'age']);\n\n// Create each hash by sending only its values.\nconst res1 = await client.hImportSet('user:1', 'user', ['Alice', 'alice@example.com', '34']);\nconsole.log(res1); // >>> OK\n\nawait client.hImportSet('user:2', 'user', ['Bob', 'bob@example.com', '41']);\nawait client.hImportSet('user:3', 'user', ['Carol', 'carol@example.com', '29']);\n\n// The result is an ordinary hash.\nconst res2 = await client.hGetAll('user:2');\nconsole.log(res2);\n// >>> { age: '41', name: 'Bob', email: 'bob@example.com' }",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex11",
      "language": "javascript",
      "code": "// Declare the field names once, when you create the client.\nconst redis = new Redis({\n  himportFieldsets: [{ name: 'user', fields: ['name', 'email', 'age'] }],\n});\n\n// Create each hash by sending only its values.\nconst res1 = await redis.himport('SET', 'user:1', 'user', 'Alice', 'alice@example.com', '34');\nconsole.log(res1); // >>> OK\n\nawait redis.himport('SET', 'user:2', 'user', 'Bob', 'bob@example.com', '41');\nawait redis.himport('SET', 'user:3', 'user', 'Carol', 'carol@example.com', '29');\n\n// The result is an ordinary hash.\nconst res2 = await redis.hgetall('user:2');\nconsole.log(res2);\n// >>> { age: '41', name: 'Bob', email: 'bob@example.com' }",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex12",
      "language": "javascript",
      "code": "// Declare the field names once.\nawait client.hImportPrepare('user', ['name', 'email', 'age']);\n\n// Create each hash by sending only its values.\nconst res1 = await client.hImportSet('user:1', 'user', ['Alice', 'alice@example.com', '34']);\nconsole.log(res1); // >>> OK\n\nawait client.hImportSet('user:2', 'user', ['Bob', 'bob@example.com', '41']);\nawait client.hImportSet('user:3', 'user', ['Carol', 'carol@example.com', '29']);\n\n// The result is an ordinary hash.\nconst res2 = await client.hGetAll('user:2');\nconsole.log(res2);\n// >>> { age: '41', name: 'Bob', email: 'bob@example.com' }",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex13",
      "language": "javascript",
      "code": "// Declare the field names once, when you create the client.\nconst redis = new Redis({\n  himportFieldsets: [{ name: 'user', fields: ['name', 'email', 'age'] }],\n});\n\n// Create each hash by sending only its values.\nconst res1 = await redis.himport('SET', 'user:1', 'user', 'Alice', 'alice@example.com', '34');\nconsole.log(res1); // >>> OK\n\nawait redis.himport('SET', 'user:2', 'user', 'Bob', 'bob@example.com', '41');\nawait redis.himport('SET', 'user:3', 'user', 'Carol', 'carol@example.com', '29');\n\n// The result is an ordinary hash.\nconst res2 = await redis.hgetall('user:2');\nconsole.log(res2);\n// >>> { age: '41', name: 'Bob', email: 'bob@example.com' }",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex14",
      "language": "php",
      "code": "// Declare the field names once.\n        $r->himport->prepare('user', ['name', 'email', 'age']);\n\n        // Create each hash by sending only its values.\n        $res1 = $r->himport->set('user:1', 'user', ['Alice', 'alice@example.com', '34']);\n        echo $res1 . PHP_EOL; // >>> OK\n\n        $r->himport->set('user:2', 'user', ['Bob', 'bob@example.com', '41']);\n        $r->himport->set('user:3', 'user', ['Carol', 'carol@example.com', '29']);\n\n        // The result is an ordinary hash.\n        $res2 = $r->hgetall('user:2');\n        echo json_encode($res2) . PHP_EOL;\n        // >>> {\"age\":\"41\",\"name\":\"Bob\",\"email\":\"bob@example.com\"}",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex15",
      "language": "python",
      "code": "# Declare the field names once.\nr.himport_prepare(\"user\", [\"name\", \"email\", \"age\"])\n\n# Create each hash by sending only its values.\nres1 = r.himport_set(\"user:1\", \"user\", [\"Alice\", \"alice@example.com\", \"34\"])\nprint(res1)\n# >>> True\n\nr.himport_set(\"user:2\", \"user\", [\"Bob\", \"bob@example.com\", \"41\"])\nr.himport_set(\"user:3\", \"user\", [\"Carol\", \"carol@example.com\", \"29\"])\n\n# The result is an ordinary hash.\nres2 = r.hgetall(\"user:2\")\nprint(res2)\n# >>> {'age': '41', 'name': 'Bob', 'email': 'bob@example.com'}",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex16",
      "language": "ruby",
      "code": "# Declare the field names once.\nr.himport_prepare('user', %w[name email age])\n\n# Create each hash by sending only its values.\nres1 = r.himport_set('user:1', 'user', ['Alice', 'alice@example.com', '34'])\nputs res1 # >>> OK\n\nr.himport_set('user:2', 'user', ['Bob', 'bob@example.com', '41'])\nr.himport_set('user:3', 'user', ['Carol', 'carol@example.com', '29'])\n\n# The result is an ordinary hash.\nres2 = r.hgetall('user:2')\nputs res2.inspect\n# >>> {\"age\" => \"41\", \"name\" => \"Bob\", \"email\" => \"bob@example.com\"}",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex17",
      "language": "plaintext",
      "code": "> HIMPORT PREPARE user name email age\nOK\n> HIMPORT SET user:1000 user user1000 user1000@example.com 20\nOK\n> HGET user:1000 email\n\"user1000@example.com\"",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex18",
      "language": "csharp",
      "code": "await using var bulkFields = HashImport.Create(\"name\", \"email\", \"age\");\n\n        // Start many imports without awaiting each one, so they share round trips.\n        var imports = new List<Task>();\n\n        for (int i = 1; i <= 1000; i++)\n        {\n            imports.Add(db.HashImportAsync(\n                $\"user:{i}\",\n                bulkFields,\n                new RedisValue[] { $\"user{i}\", $\"user{i}@example.com\", (20 + i % 50).ToString() }\n            ));\n        }\n\n        await Task.WhenAll(imports);\n\n        int res2 = imports.Count(t => t.Status == TaskStatus.RanToCompletion);\n        Console.WriteLine(res2);    // >>> 1000\n\n        RedisValue res3 = await db.HashGetAsync(\"user:1000\", \"email\");\n        Console.WriteLine(res3);    // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex19",
      "language": "csharp",
      "code": "using var bulkFields = HashImport.Create(\"name\", \"email\", \"age\");\n\n        // Queue many imports and send them in one round trip.\n        var batch = db.CreateBatch();\n        var imports = new List<Task>();\n\n        for (int i = 1; i <= 1000; i++)\n        {\n            imports.Add(batch.HashImportAsync(\n                $\"user:{i}\",\n                bulkFields,\n                new RedisValue[] { $\"user{i}\", $\"user{i}@example.com\", (20 + i % 50).ToString() }\n            ));\n        }\n\n        batch.Execute();\n        Task.WaitAll(imports.ToArray());\n\n        int res2 = imports.Count(t => t.Status == TaskStatus.RanToCompletion);\n        Console.WriteLine(res2);    // >>> 1000\n\n        RedisValue res3 = db.HashGet(\"user:1000\", \"email\");\n        Console.WriteLine(res3);    // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex20",
      "language": "csharp",
      "code": "await using var bulkFields = HashImport.Create(\"name\", \"email\", \"age\");\n\n        // Start many imports without awaiting each one, so they share round trips.\n        var imports = new List<Task>();\n\n        for (int i = 1; i <= 1000; i++)\n        {\n            imports.Add(db.HashImportAsync(\n                $\"user:{i}\",\n                bulkFields,\n                new RedisValue[] { $\"user{i}\", $\"user{i}@example.com\", (20 + i % 50).ToString() }\n            ));\n        }\n\n        await Task.WhenAll(imports);\n\n        int res2 = imports.Count(t => t.Status == TaskStatus.RanToCompletion);\n        Console.WriteLine(res2);    // >>> 1000\n\n        RedisValue res3 = await db.HashGetAsync(\"user:1000\", \"email\");\n        Console.WriteLine(res3);    // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex21",
      "language": "csharp",
      "code": "using var bulkFields = HashImport.Create(\"name\", \"email\", \"age\");\n\n        // Queue many imports and send them in one round trip.\n        var batch = db.CreateBatch();\n        var imports = new List<Task>();\n\n        for (int i = 1; i <= 1000; i++)\n        {\n            imports.Add(batch.HashImportAsync(\n                $\"user:{i}\",\n                bulkFields,\n                new RedisValue[] { $\"user{i}\", $\"user{i}@example.com\", (20 + i % 50).ToString() }\n            ));\n        }\n\n        batch.Execute();\n        Task.WaitAll(imports.ToArray());\n\n        int res2 = imports.Count(t => t.Status == TaskStatus.RanToCompletion);\n        Console.WriteLine(res2);    // >>> 1000\n\n        RedisValue res3 = db.HashGet(\"user:1000\", \"email\");\n        Console.WriteLine(res3);    // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex22",
      "language": "go",
      "code": "if err := rdb.HImportPrepare(ctx, \"user\", \"name\", \"email\", \"age\").Err(); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Queue many imports and send them in one round trip.\n\tpipe := rdb.Pipeline()\n\tfor i := 1; i <= 1000; i++ {\n\t\tpipe.HImportSet(ctx, fmt.Sprintf(\"user:%d\", i), \"user\",\n\t\t\tfmt.Sprintf(\"user%d\", i), fmt.Sprintf(\"user%d@example.com\", i), fmt.Sprint(20+i%50))\n\t}\n\tres3, err := pipe.Exec(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tallOK := true\n\tfor _, cmd := range res3 {\n\t\tif cmd.Err() != nil {\n\t\t\tallOK = false\n\t\t}\n\t}\n\tfmt.Println(len(res3), allOK) // >>> 1000 true\n\n\tres4, err := rdb.HGet(ctx, \"user:1000\", \"email\").Result()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(res4) // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex23",
      "language": "java",
      "code": "List<String> res3 = new ArrayList<>();\n\n            // The sync API waits for each reply, so these imports aren't pipelined.\n            // To pipeline them, use the async or reactive API.\n            try (HashImport<String> fieldset = HashImport.of(\"name\", \"email\", \"age\")) {\n                for (int i = 1; i <= 1000; i++) {\n                    res3.add(syncCommands.himportSet(\"user:\" + i, fieldset,\n                            \"user\" + i, \"user\" + i + \"@example.com\", String.valueOf(20 + i % 50)));\n                }\n            }\n\n            boolean allOk = res3.stream().allMatch(\"OK\"::equals);\n            System.out.println(res3.size() + \" \" + allOk); // >>> 1000 true\n\n            String res4 = syncCommands.hget(\"user:1000\", \"email\");\n            System.out.println(res4); // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex24",
      "language": "java",
      "code": "List<RedisFuture<String>> res3 = new ArrayList<>();\n\n            // Issue many imports without waiting for each reply.\n            try (HashImport<String> fieldset = HashImport.of(\"name\", \"email\", \"age\")) {\n                for (int i = 1; i <= 1000; i++) {\n                    res3.add(asyncCommands.himportSet(\"user:\" + i, fieldset,\n                            \"user\" + i, \"user\" + i + \"@example.com\", String.valueOf(20 + i % 50)));\n                }\n            }\n\n            LettuceFutures.awaitAll(5, TimeUnit.SECONDS, res3.toArray(new RedisFuture[0]));\n\n            boolean allOk = res3.stream().allMatch(f -> \"OK\".equals(f.toCompletableFuture().join()));\n            System.out.println(res3.size() + \" \" + allOk); // >>> 1000 true\n\n            CompletableFuture<Void> getEmail = asyncCommands.hget(\"user:1000\", \"email\")\n                .thenAccept(res4 -> {\n                    System.out.println(res4); // >>> user1000@example.com\n                })\n                .toCompletableFuture();\n\n            getEmail.join();",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex25",
      "language": "java",
      "code": "List<String> res3;\n\n            // Issue many imports without waiting for each reply.\n            try (HashImport<String> fieldset = HashImport.of(\"name\", \"email\", \"age\")) {\n                res3 = Flux.range(1, 1000)\n                    .flatMap(i -> reactiveCommands.himportSet(\"user:\" + i, fieldset,\n                            \"user\" + i, \"user\" + i + \"@example.com\", String.valueOf(20 + i % 50)))\n                    .collectList()\n                    .block();\n            }\n\n            boolean allOk = res3.stream().allMatch(\"OK\"::equals);\n            System.out.println(res3.size() + \" \" + allOk); // >>> 1000 true\n\n            Mono<String> getEmail = reactiveCommands.hget(\"user:1000\", \"email\").doOnNext(res4 -> {\n                System.out.println(res4); // >>> user1000@example.com\n            });\n\n            getEmail.block();",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex26",
      "language": "java",
      "code": "List<Response<String>> res3 = new ArrayList<>();\n\n        // Queue many imports and send them in one round trip.\n        try (HashImport fields = HashImport.of(\"name\", \"email\", \"age\");\n                Pipeline pipeline = jedis.pipelined()) {\n            for (int i = 1; i <= 1000; i++) {\n                res3.add(pipeline.himportSet(\"user:\" + i, fields,\n                        \"user\" + i, \"user\" + i + \"@example.com\", String.valueOf(20 + i % 50)));\n            }\n            pipeline.sync();\n        }\n\n        boolean allOk = res3.stream().allMatch(r -> \"OK\".equals(r.get()));\n        System.out.println(res3.size() + \" \" + allOk); // >>> 1000 true\n\n        String res4 = jedis.hget(\"user:1000\", \"email\");\n        System.out.println(res4); // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex27",
      "language": "javascript",
      "code": "await client.hImportPrepare('user', ['name', 'email', 'age']);\n\n// Commands issued together are automatically pipelined.\nconst imports = [];\nfor (let i = 1; i <= 1000; i++) {\n  imports.push(\n    client.hImportSet(`user:${i}`, 'user', [`user${i}`, `user${i}@example.com`, String(20 + i % 50)])\n  );\n}\nconst res3 = await Promise.all(imports);\n\nconsole.log(res3.length, res3.every((r) => r === 'OK'));\n// >>> 1000 true\n\nconst res4 = await client.hGet('user:1000', 'email');\nconsole.log(res4); // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex28",
      "language": "javascript",
      "code": "const redis = new Redis({\n  himportFieldsets: [{ name: 'user', fields: ['name', 'email', 'age'] }],\n});\n\n// Queue many imports and send them in one round trip.\nconst pipeline = redis.pipeline();\nfor (let i = 1; i <= 1000; i++) {\n  pipeline.himport('SET', `user:${i}`, 'user', `user${i}`, `user${i}@example.com`, String(20 + i % 50));\n}\nconst res3 = await pipeline.exec();\n\nconsole.log(res3.length, res3.every(([err]) => err === null));\n// >>> 1000 true\n\nconst res4 = await redis.hget('user:1000', 'email');\nconsole.log(res4); // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex29",
      "language": "javascript",
      "code": "await client.hImportPrepare('user', ['name', 'email', 'age']);\n\n// Commands issued together are automatically pipelined.\nconst imports = [];\nfor (let i = 1; i <= 1000; i++) {\n  imports.push(\n    client.hImportSet(`user:${i}`, 'user', [`user${i}`, `user${i}@example.com`, String(20 + i % 50)])\n  );\n}\nconst res3 = await Promise.all(imports);\n\nconsole.log(res3.length, res3.every((r) => r === 'OK'));\n// >>> 1000 true\n\nconst res4 = await client.hGet('user:1000', 'email');\nconsole.log(res4); // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex30",
      "language": "javascript",
      "code": "const redis = new Redis({\n  himportFieldsets: [{ name: 'user', fields: ['name', 'email', 'age'] }],\n});\n\n// Queue many imports and send them in one round trip.\nconst pipeline = redis.pipeline();\nfor (let i = 1; i <= 1000; i++) {\n  pipeline.himport('SET', `user:${i}`, 'user', `user${i}`, `user${i}@example.com`, String(20 + i % 50));\n}\nconst res3 = await pipeline.exec();\n\nconsole.log(res3.length, res3.every(([err]) => err === null));\n// >>> 1000 true\n\nconst res4 = await redis.hget('user:1000', 'email');\nconsole.log(res4); // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex31",
      "language": "php",
      "code": "// Queue many imports and send them in one round trip. The fieldset is\n        // declared inside the pipeline so it runs on the same connection.\n        $replies = $r->pipeline(function ($pipe) {\n            $pipe->himport('PREPARE', 'user', ['name', 'email', 'age']);\n\n            for ($i = 1; $i <= 1000; $i++) {\n                $pipe->himport('SET', \"user:$i\", 'user', [\"user$i\", \"user$i@example.com\", (string) (20 + $i % 50)]);\n            }\n        });\n\n        // The first reply is for PREPARE.\n        $res3 = array_slice($replies, 1);\n        $allOk = true;\n        foreach ($res3 as $reply) {\n            $allOk = $allOk && $reply == 'OK';\n        }\n        echo count($res3) . ' ' . var_export($allOk, true) . PHP_EOL; // >>> 1000 true\n\n        $res4 = $r->hget('user:1000', 'email');\n        echo $res4 . PHP_EOL; // >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex32",
      "language": "python",
      "code": "r.himport_prepare(\"user\", [\"name\", \"email\", \"age\"])\n\n# Queue many imports and send them in one round trip.\nwith r.pipeline(transaction=False) as pipe:\n    for i in range(1, 1001):\n        pipe.himport_set(\n            f\"user:{i}\", \"user\", [f\"user{i}\", f\"user{i}@example.com\", str(20 + i % 50)]\n        )\n    res3 = pipe.execute()\n\nprint(len(res3), all(res3))\n# >>> 1000 True\n\nres4 = r.hget(\"user:1000\", \"email\")\nprint(res4)\n# >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex33",
      "language": "ruby",
      "code": "# Queue many imports and send them in one round trip. The fieldset is\n# declared inside the pipeline so it runs on the same connection.\nreplies = r.pipelined do |pipe|\n  pipe.himport_prepare('user', %w[name email age])\n  (1..1000).each do |i|\n    pipe.himport_set(\"user:#{i}\", 'user', [\"user#{i}\", \"user#{i}@example.com\", (20 + i % 50).to_s])\n  end\nend\n\n# The first reply is for PREPARE.\nres3 = replies.drop(1)\nputs \"#{res3.length} #{res3.all?('OK')}\" # >>> 1000 true\n\nres4 = r.hget('user:1000', 'email')\nputs res4 # >>> user1000@example.com",
      "section_id": "bulk-import-with-himport"
    }
  ]
}
