{
  "schema_version": 2,
  "id": "commands/hdel",
  "title": "HDEL",
  "url": "https://redis.io/docs/latest/commands/hdel/",
  "summary": "Deletes one or more fields and their values from a hash. Deletes the hash if no fields remain.",
  "since": "2.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-07-08T12:05:04+02:00",
  "page_type": "content",
  "content_hash": "efc65699c2ff01c986cbacbcceed05e63d01792b51415003d9ca942d506a7a31",
  "sections": [
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key that holds the hash.\n\n</details>\n\n<details open><summary><code>field [field ...]</code></summary>\n\nOne or more fields to delete from the hash.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Foundational: Delete one or more fields from a hash using HDEL (returns count of deleted fields, ignores non-existent fields)\n\n**Difficulty:** Beginner\n\n**Commands:** HSET, HDEL\n\n**Complexity:**\n- HSET: O(1)\n- HDEL: 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, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\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##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]"
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> | <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the number of fields that were removed from the hash, excluding any specified but non-existing fields.\n\n**RESP3:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): The number of fields that were removed from the hash, excluding any specified but non-existing fields."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> HSET myhash field1 \"foo\"\n(integer) 1\n> HDEL myhash field1\n(integer) 1\n> HDEL myhash field2\n(integer) 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "c",
      "code": "reply = redisCommand(c, \"HSET myhash field1 foo\");\n    printf(\"%lld\\n\", reply->integer);\n    // >>> 1\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"HDEL myhash field1\");\n    printf(\"%lld\\n\", reply->integer);\n    // >>> 1\n    freeReplyObject(reply);\n\n    // Deleting a field that is not there removes nothing.\n    reply = redisCommand(c, \"HDEL myhash field2\");\n    printf(\"%lld\\n\", reply->integer);\n    // >>> 0\n    freeReplyObject(reply);",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "csharp",
      "code": "bool hdelRes1 = db.HashSet(\"myhash\", \"field1\", \"foo\");\n\n        RedisValue hdelRes2 = db.HashDelete(\"myhash\", \"field1\");\n        Console.WriteLine(hdelRes2);    // >>> 1\n\n        RedisValue hdelRes3 = db.HashDelete(\"myhash\", \"field1\");\n        Console.WriteLine(hdelRes3);    // >>> 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "go",
      "code": "hdel1, err := rdb.HSet(ctx, \"myhash\", \"field1\", \"foo\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(hdel1) // >>> 1\n\n\thdel2, err := rdb.HDel(ctx, \"myhash\", \"field1\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(hdel2) // >>> 1\n\n\thdel3, err := rdb.HDel(ctx, \"myhash\", \"field2\").Result()\n\n\tif err != nil {\n\t\tfmt.Println(err)\n\t}\n\n\tfmt.Println(hdel3) // >>> 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "// `hset` returns true because `field1` is a new field.\n            boolean res1 = syncCommands.hset(\"myhash\", \"field1\", \"foo\");\n            System.out.println(res1); // >>> true\n\n            Long res2 = syncCommands.hdel(\"myhash\", \"field1\");\n            System.out.println(res2); // >>> 1\n\n            // `hdel` returns 0 because `field2` doesn't exist.\n            Long res3 = syncCommands.hdel(\"myhash\", \"field2\");\n            System.out.println(res3); // >>> 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "Map<String, String> hDelExampleParams = new HashMap<>();\n            hDelExampleParams.put(\"field1\", \"foo\");\n\n            CompletableFuture<Void> hDelExample = asyncCommands.hset(\"myhash\", hDelExampleParams).thenCompose(res1 -> {\n                System.out.println(res1); // >>> 1\n                return asyncCommands.hdel(\"myhash\", \"field1\");\n            }).thenCompose(res2 -> {\n                System.out.println(res2); // >>> 1\n                return asyncCommands.hdel(\"myhash\", \"field2\");\n            }).thenAccept(res3 -> {\n                System.out.println(res3); // >>> 0\n            }).toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "java",
      "code": "Map<String, String> hDelExampleParams = new HashMap<>();\n            hDelExampleParams.put(\"field1\", \"foo\");\n\n            Mono<Long> hDelExample1 = reactiveCommands.hset(\"myhash\", hDelExampleParams).doOnNext(result -> {\n                System.out.println(result); // >>> 1\n            });\n\n            hDelExample1.block();\n\n            Mono<Long> hDelExample2 = reactiveCommands.hdel(\"myhash\", \"field1\").doOnNext(result -> {\n                System.out.println(result); // >>> 1\n            });\n\n            hDelExample2.block();\n\n            Mono<Long> hDelExample3 = reactiveCommands.hdel(\"myhash\", \"field2\").doOnNext(result -> {\n                System.out.println(result); // >>> 0\n            });",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "java",
      "code": "Map<String, String> hDelExampleParams = new HashMap<>();\n        hDelExampleParams.put(\"field1\", \"foo\");\n\n        long hDelResult1 = jedis.hset(\"myhash\", hDelExampleParams);\n        System.out.println(hDelResult1);    // >>> 1\n\n        long hDelResult2 = jedis.hdel(\"myhash\", \"field1\");\n        System.out.println(hDelResult2);    // >>> 1\n\n        long hDelResult3 = jedis.hdel(\"myhash\", \"field2\");\n        System.out.println(hDelResult3);    // >>> 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "javascript",
      "code": "const hDel1 = await client.hSet('myhash', 'field1', 'Hello')\nconsole.log(hDel1) // 1\n\nconst hDel2 = await client.hDel('myhash', 'field1')\nconsole.log(hDel2) // 1\n\nconst hDel3 = await client.hDel('myhash', 'field2')\nconsole.log(hDel3) // 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "javascript",
      "code": "const hdelRes1 = await redis.hset('myhash', 'field1', 'foo');\nconsole.log(hdelRes1); // >>> 1\n\nconst hdelRes2 = await redis.hdel('myhash', 'field1');\nconsole.log(hdelRes2); // >>> 1\n\n// Deleting a field that is not there removes nothing.\nconst hdelRes3 = await redis.hdel('myhash', 'field2');\nconsole.log(hdelRes3); // >>> 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "javascript",
      "code": "const hDel1 = await client.hSet('myhash', 'field1', 'Hello')\nconsole.log(hDel1) // 1\n\nconst hDel2 = await client.hDel('myhash', 'field1')\nconsole.log(hDel2) // 1\n\nconst hDel3 = await client.hDel('myhash', 'field2')\nconsole.log(hDel3) // 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "javascript",
      "code": "const hdelRes1 = await redis.hset('myhash', 'field1', 'foo');\nconsole.log(hdelRes1); // >>> 1\n\nconst hdelRes2 = await redis.hdel('myhash', 'field1');\nconsole.log(hdelRes2); // >>> 1\n\n// Deleting a field that is not there removes nothing.\nconst hdelRes3 = await redis.hdel('myhash', 'field2');\nconsole.log(hdelRes3); // >>> 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex12",
      "language": "php",
      "code": "$hDelResult1 = $this->redis->hset('myhash', 'field1', 'foo');\n        echo \"HSET myhash field1 foo: \" . $hDelResult1 . \"\\n\"; // >>> 1\n\n        $hDelResult2 = $this->redis->hdel('myhash', 'field1');\n        echo \"HDEL myhash field1: \" . $hDelResult2 . \"\\n\"; // >>> 1\n\n        $hDelResult3 = $this->redis->hdel('myhash', 'field2');\n        echo \"HDEL myhash field2: \" . $hDelResult3 . \"\\n\"; // >>> 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex13",
      "language": "python",
      "code": "hdel1 = r.hset(\"myhash\", \"field1\", \"foo\")\nprint(hdel1)\n# >>> 1\n\nhdel2 = r.hdel(\"myhash\", \"field1\")\nprint(hdel2)\n# >>> 1\n\nhdel3 = r.hdel(\"myhash\", \"field2\")\nprint(hdel3)\n# >>> 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex14",
      "language": "ruby",
      "code": "res1 = r.hset('myhash', 'field1', 'foo')\nputs res1 # >>> 1\n\nres2 = r.hdel('myhash', 'field1')\nputs res2 # >>> 1\n\nres3 = r.hdel('myhash', 'field2')\nputs res3 # >>> 0",
      "section_id": "examples"
    },
    {
      "id": "examples-ex15",
      "language": "rust",
      "code": "match r.hset(\"myhash\", \"field1\", \"foo\").await {\n            Ok(hdel1) => {\n                let hdel1: i32 = hdel1;\n                println!(\"{hdel1}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error setting hash field: {e}\");\n                return;\n            }\n        }\n\n        match r.hdel(\"myhash\", \"field1\").await {\n            Ok(hdel2) => {\n                let hdel2: Option<i32> = hdel2;\n                match hdel2 {\n                    Some(value) => {\n                        println!(\"{value}\");    // >>> 1\n                    },\n                    None => {\n                        println!(\"None\");\n                    }\n                }\n            },\n            Err(e) => {\n                println!(\"Error getting hash field: {e}\");\n                return;\n            }\n        }\n\n        match r.hdel(\"myhash\", \"field2\").await {\n            Ok(hdel3) => {\n                let hdel3: Option<i32> = hdel3;\n                match hdel3 {\n                    Some(value) => {\n                        println!(\"{value}\");    // >>> 0\n                    },\n                    None => {\n                        println!(\"None\");\n                    }\n                }\n            },\n            Err(e) => {\n                println!(\"Error getting hash field: {e}\");\n                return;\n            }\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex16",
      "language": "rust",
      "code": "match r.hset(\"myhash\", \"field1\", \"foo\") {\n            Ok(hdel1) => {\n                let hdel1: i32 = hdel1;\n                println!(\"{hdel1}\");    // >>> 1\n            },\n            Err(e) => {\n                println!(\"Error setting hash field: {e}\");\n                return;\n            }\n        }\n\n        match r.hdel(\"myhash\", \"field1\") {\n            Ok(hdel2) => {\n                let hdel2: Option<i32> = hdel2;\n                match hdel2 {\n                    Some(value) => {\n                        println!(\"{value}\");    // >>> 1\n                    },\n                    None => {\n                        println!(\"None\");\n                    }\n                }\n            },\n            Err(e) => {\n                println!(\"Error getting hash field: {e}\");\n                return;\n            }\n        }\n\n        match r.hdel(\"myhash\", \"field2\") {\n            Ok(hdel3) => {\n                let hdel3: Option<i32> = hdel3;\n                match hdel3 {\n                    Some(value) => {\n                        println!(\"{value}\");    // >>> 0\n                    },\n                    None => {\n                        println!(\"None\");\n                    }\n                }\n            },\n            Err(e) => {\n                println!(\"Error getting hash field: {e}\");\n                return;\n            }\n        }",
      "section_id": "examples"
    }
  ]
}
