> ## 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.

# HGETEX

> Get hash fields with expiration support.

The `HGETEX` command returns the values of the specified fields and optionally sets their expiration time or TTL. This allows you to retrieve hash data while managing its lifetime in a single 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.
</ParamField>

<ParamField body="ex" type="int">
  Set expiration time in seconds.
</ParamField>

<ParamField body="px" type="int">
  Set expiration time in milliseconds.
</ParamField>

<ParamField body="exat" type="int">
  Set expiration as Unix timestamp in seconds.
</ParamField>

<ParamField body="pxat" type="int">
  Set expiration as Unix timestamp in milliseconds.
</ParamField>

<ParamField body="persist" type="bool">
  Remove expiration from the hash.
</ParamField>

## Response

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

<RequestExample>
  ```py With EX (seconds) theme={"system"}
  redis.hset("user:123", values={"name": "John", "email": "john@example.com"})

  # Get fields and set expiration to 60 seconds
  result = redis.hgetex("user:123", "name", "email", ex=60)
  assert result == ["John", "john@example.com"]
  ```

  ```py With PX (milliseconds) theme={"system"}
  redis.hset("session:abc", values={"token": "xyz123", "user": "john"})

  # Get fields and set expiration to 30000 milliseconds (30 seconds)
  result = redis.hgetex("session:abc", "token", "user", px=30000)
  assert result == ["xyz123", "john"]
  ```

  ```py With EXAT (Unix timestamp in seconds) theme={"system"}
  import time

  redis.hset("cache:data", "value", "cached")

  # Set expiration to specific timestamp (1 hour from now)
  future_time = int(time.time()) + 3600
  result = redis.hgetex("cache:data", "value", exat=future_time)
  assert result == ["cached"]
  ```

  ```py With PXAT (Unix timestamp in milliseconds) theme={"system"}
  import time

  redis.hset("temp:data", "info", "temporary")

  # Set expiration to specific timestamp in milliseconds
  future_time = int(time.time() * 1000) + 60000  # 1 minute from now
  result = redis.hgetex("temp:data", "info", pxat=future_time)
  assert result == ["temporary"]
  ```

  ```py With PERSIST theme={"system"}
  redis.hset("user:456", "name", "Jane")
  redis.expire("user:456", 300)  # Set 5 minute expiration

  # Get fields and remove expiration
  result = redis.hgetex("user:456", "name", persist=True)
  assert result == ["Jane"]

  # Verify expiration was removed
  ttl = redis.ttl("user:456")
  assert ttl == -1  # No expiration
  ```

  ```py Without Options theme={"system"}
  redis.hset("data:xyz", values={"field1": "value1", "field2": "value2"})

  # Just get fields without changing expiration
  result = redis.hgetex("data:xyz", "field1", "field2")
  assert result == ["value1", "value2"]
  ```

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

  # Get fields including one that doesn't exist
  result = redis.hgetex("user:789", "name", "email")
  assert result == ["Bob", None]
  ```
</RequestExample>

## Use Cases

* **Session Management**: Retrieve session data and extend its lifetime
* **Cache Refresh**: Get cached data and update its TTL
* **Temporary Data**: Access temporary data while managing its expiration
* **Rate Limiting**: Fetch rate limit data and reset expiration
