> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# HGETDEL

> Get and delete hash fields atomically.

The `HGETDEL` command returns the values of the specified fields and then atomically deletes them from the hash. This is useful when you need to retrieve and remove data in a single atomic operation.

## Arguments

<ParamField body="key" type="string" required>
  The key of the hash.
</ParamField>

<ParamField body="fields" type="...string[]" required>
  One or more field names to get and delete.
</ParamField>

## Response

<ResponseField type="Record<string, TValue | null> | null" required>
  An object containing the field names and their values in the format `{[fieldName: string]: TValue | null}`. Returns `null` for fields that do not exist. If the hash doesn't exist or all fields are non-existent, `null` is returned.
</ResponseField>

<RequestExample>
  ```ts Basic Example theme={"system"}
  // Set some hash fields
  await redis.hset("user:123", { name: "John", age: "30", email: "john@example.com" });

  // Get and delete specific fields
  const result = await redis.hgetdel("user:123", "name", "email");
  console.log(result); // { name: "John", email: "john@example.com" }

  // Verify fields were deleted
  const name = await redis.hget("user:123", "name");
  console.log(name); // null
  ```

  ```ts Multiple Fields theme={"system"}
  await redis.hset("session:abc", { 
    token: "xyz123", 
    user: "john", 
    expires: "2024-12-31" 
  });

  // Get and delete all fields
  const session = await redis.hgetdel("session:abc", "token", "user", "expires");
  console.log(session); 
  // { token: "xyz123", user: "john", expires: "2024-12-31" }
  ```

  ```ts Non-existent Fields theme={"system"}
  await redis.hset("user:456", { name: "Jane" });

  // Get and delete with non-existent field
  const result = await redis.hgetdel("user:456", "name", "email");
  console.log(result); // { name: "Jane", email: null }
  ```
</RequestExample>

## Use Cases

* **Session Management**: Retrieve and invalidate session data atomically
* **Cache Cleanup**: Get cached data while removing it from storage
* **Queue Processing**: Fetch and remove job data in a single operation
* **Temporary Data**: Retrieve one-time use tokens or codes while deleting them
