# HPEXPIRE

> Sets an expiration time for a field in a hash in milliseconds.

## Arguments

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

<ParamField body="fields" type="string | number | (string | number)[]" required>
  The field or list of fields within the hash to set the expiry for.
</ParamField>

<ParamField body="milliseconds" type="number" required>
  The time-to-live (TTL) in milliseconds.
</ParamField>

<ParamField body="option" type="string" optional>
  Optional condition for setting the expiration:
  - `NX`: Set the expiration only if the field does not already have an expiration.
  - `XX`: Set the expiration only if the field already has an expiration.
  - `GT`: Set the expiration only if the new TTL is greater than the current TTL.
  - `LT`: Set the expiration only if the new TTL is less than the current TTL.

  For more details, see [HPEXPIRE documentation](https://redis.io/commands/hpexpire).
</ParamField>

## Response

<ResponseField type="number[]" required>
  A list of integers indicating whether the expiry was successfully set.

  - `-2` if the field does not exist in the hash or if key doesn't exist.
  - `0` if the expiration was not set due to the condition.
  - `1` if the expiration was successfully set.
  - `2` if called with 0 seconds/milliseconds or a past Unix time.

  For more details, see [HPEXPIRE documentation](https://redis.io/commands/hpexpire).
</ResponseField>

<RequestExample>
```ts Example
await redis.hset("my-key", "my-field", "my-value");
const expirationSet = await redis.hpexpire("my-key", "my-field", 1000);

console.log(expirationSet); // [1]
```
</RequestExample>
