> ## 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="str" required>
  The key of the hash.
</ParamField>

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

## Response

<ResponseField type="Optional[List[str | None]]">
  A list of values corresponding to the requested fields, in the same order as the field arguments. For fields that do not exist, `None` is returned in that position. If the hash doesn't exist, `None` is returned.
</ResponseField>

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

  # Get and delete specific fields
  result = redis.hgetdel("user:123", "name", "email")
  assert result == ["John", "john@example.com"]

  # Verify fields were deleted
  assert redis.hget("user:123", "name") is None
  ```

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

  # Get and delete all fields
  session = redis.hgetdel("session:abc", "token", "user", "expires")
  assert session == ["xyz123", "john", "2024-12-31"]
  ```

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

  # Get and delete with non-existent field
  result = redis.hgetdel("user:456", "name", "email")
  assert result == ["Jane", None]
  ```

  ```py Non-existent Hash theme={"system"}
  # Returns None if hash doesn't exist
  result = redis.hgetdel("nonexistent", "field1")
  assert result is None
  ```
</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
