{
  "schema_version": 2,
  "id": "commands/del",
  "title": "DEL",
  "url": "https://redis.io/docs/latest/commands/del/",
  "summary": "Deletes one or more keys.",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:32+01:00",
  "page_type": "content",
  "content_hash": "9056d045f346458c953ea01f6284db6916463e51087bdd9c0ab6c9246338d5e9",
  "sections": [
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key [key ...]</code></summary>\n\nOne or more keys to delete.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Foundational: Delete one or more keys using DEL (ignores non-existent keys, returns count of deleted keys)\n\n**Difficulty:** Beginner\n\n**Commands:** SET, DEL\n\n**Complexity:**\n- SET: O(1)\n- DEL: O(N)\n\n**Available in:** Redis CLI, C, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C\n\n[code example]\n\n##### C#\n\n[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##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]"
    },
    {
      "id": "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 keys that were removed.\n\n**RESP3:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the number of keys that were removed."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> SET key1 \"Hello\"\nOK\n> SET key2 \"World\"\nOK\n> DEL key1 key2 key3\n(integer) 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "c",
      "code": "reply = redisCommand(c, \"SET key1 Hello\");\n    printf(\"%s\\n\", reply->str);\n    // >>> OK\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"SET key2 World\");\n    printf(\"%s\\n\", reply->str);\n    // >>> OK\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"DEL key1 key2 key3\");\n    printf(\"%lld\\n\", reply->integer);\n    // >>> 2\n    freeReplyObject(reply);",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "csharp",
      "code": "bool delResult1 = db.StringSet(\"key1\", \"Hello\");\n        Console.WriteLine(delResult1);  // >>> true\n\n        bool delResult2 = db.StringSet(\"key2\", \"World\");\n        Console.WriteLine(delResult2);  // >>> true\n\n        long delResult3 = db.KeyDelete([\"key1\", \"key2\", \"key3\"]);\n        Console.WriteLine(delResult3);  // >>> 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "go",
      "code": "delResult1, err := rdb.Set(ctx, \"key1\", \"Hello\", 0).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(delResult1) // >>> OK\n\n\tdelResult2, err := rdb.Set(ctx, \"key2\", \"World\", 0).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(delResult2) // >>> OK\n\n\tdelResult3, err := rdb.Del(ctx, \"key1\", \"key2\", \"key3\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(delResult3) // >>> 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "CompletableFuture<Void> delExample = asyncCommands.set(\"key1\", \"Hello\")\n                    .thenCompose(r1 -> {\n                        System.out.println(r1);              // >>> OK\n                        return asyncCommands.set(\"key2\", \"World\");\n                    })\n                    .thenCompose(r2 -> {\n                        System.out.println(r2);              // >>> OK\n                        return asyncCommands.del(\"key1\", \"key2\", \"key3\");\n                    })\n                    .thenAccept(r3 -> {\n                        System.out.println(r3);              // >>> 2\n                    })\n                    .toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "Mono<Void> delExample = reactiveCommands.set(\"key1\", \"Hello\")\n                    .flatMap(r1 -> {\n                        System.out.println(r1);              // >>> OK\n                        return reactiveCommands.set(\"key2\", \"World\");\n                    })\n                    .flatMap(r2 -> {\n                        System.out.println(r2);              // >>> OK\n                        return reactiveCommands.del(\"key1\", \"key2\", \"key3\");\n                    })\n                    .doOnNext(r3 -> {\n                        System.out.println(r3);              // >>> 2\n                    })\n                    .then();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "java",
      "code": "String delResult1 = jedis.set(\"key1\", \"Hello\");\n        System.out.println(delResult1); // >>> OK\n\n        String delResult2 = jedis.set(\"key2\", \"World\");\n        System.out.println(delResult2); // >>> OK\n\n        long delResult3 = jedis.del(\"key1\", \"key2\", \"key3\");\n        System.out.println(delResult3); // >>> 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "javascript",
      "code": "const delRes1 = await client.set('key1', 'Hello');\nconsole.log(delRes1); // OK\n\nconst delRes2 = await client.set('key2', 'World');\nconsole.log(delRes2); // OK\n\nconst delRes3 = await client.del(['key1', 'key2', 'key3']);\nconsole.log(delRes3); // 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "javascript",
      "code": "console.log(await redis.set('key1', 'Hello')); // >>> OK\nconsole.log(await redis.set('key2', 'World')); // >>> OK\n\nconst delResult = await redis.del('key1', 'key2', 'key3');\nconsole.log(delResult); // >>> 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "javascript",
      "code": "const delRes1 = await client.set('key1', 'Hello');\nconsole.log(delRes1); // OK\n\nconst delRes2 = await client.set('key2', 'World');\nconsole.log(delRes2); // OK\n\nconst delRes3 = await client.del(['key1', 'key2', 'key3']);\nconsole.log(delRes3); // 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "javascript",
      "code": "console.log(await redis.set('key1', 'Hello')); // >>> OK\nconsole.log(await redis.set('key2', 'World')); // >>> OK\n\nconst delResult = await redis.del('key1', 'key2', 'key3');\nconsole.log(delResult); // >>> 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "php",
      "code": "echo $r->set('key1', 'Hello') . PHP_EOL;             // >>> OK\n        echo $r->set('key2', 'World') . PHP_EOL;             // >>> OK\n\n        $delResult = $r->del('key1', 'key2', 'key3');\n        echo $delResult . PHP_EOL;                           // >>> 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex12",
      "language": "python",
      "code": "res = r.set(\"key1\", \"Hello\")\nprint(res)\n# >>> True\n\nres = r.set(\"key2\", \"World\")\nprint(res)\n# >>> True\n\nres = r.delete(\"key1\", \"key2\", \"key3\")\nprint(res)\n# >>> 2",
      "section_id": "examples"
    },
    {
      "id": "examples-ex13",
      "language": "rust",
      "code": "if let Ok(res) = r.set(\"key1\", \"Hello\").await {\n            let res: String = res;\n            println!(\"{res}\");    // >>> OK\n        }\n\n        if let Ok(res) = r.set(\"key2\", \"World\").await {\n            let res: String = res;\n            println!(\"{res}\");    // >>> OK\n        }\n\n        match r.del(&[\"key1\", \"key2\", \"key3\"]).await {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 2\n            },\n            Err(e) => {\n                println!(\"Error deleting keys: {e}\");\n                return;\n            }\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex14",
      "language": "rust",
      "code": "if let Ok(res) = r.set(\"key1\", \"Hello\") {\n            let res: String = res;\n            println!(\"{res}\");    // >>> OK\n        }\n\n        if let Ok(res) = r.set(\"key2\", \"World\") {\n            let res: String = res;\n            println!(\"{res}\");    // >>> OK\n        }\n\n        match r.del(&[\"key1\", \"key2\", \"key3\"]) {\n            Ok(res) => {\n                let res: i32 = res;\n                println!(\"{res}\");    // >>> 2\n            },\n            Err(e) => {\n                println!(\"Error deleting keys: {e}\");\n                return;\n            }\n        }",
      "section_id": "examples"
    }
  ]
}
