# HEXPIREAT

> Make one or more hash fields expire at a Unix time in seconds.

URL: https://docs.hotkv.com/commands/hexpireat/

```
HEXPIREAT key unix-time-seconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
```

- Group: Hash
- Complexity: O(N) where N is the number of fields given
- HotKV Cloud: all plans
- On-Premise: no license needed

`HEXPIREAT` works like [HEXPIRE](https://docs.hotkv.com/commands/hexpire/index.md), but instead of a
relative time to live you give the absolute moment the fields expire, as a
Unix timestamp in seconds. A timestamp that is already in the past deletes the
fields at once (result code `2`).

## Options

| Option | Effect |
| --- | --- |
| `NX` | Set the expiry only on fields that have none. |
| `XX` | Set the expiry only on fields that already have one. |
| `GT` | Set the expiry only if it is later than the field's current one. A field without one never matches. |
| `LT` | Set the expiry only if it is earlier than the field's current one. A field without one always matches. |

## Return value

An array with one integer per field, in the order given, under both RESP2 and
RESP3:

| Code | Meaning |
| --- | --- |
| `-2` | The field or the key does not exist. |
| `0` | The condition was not met; nothing changed. |
| `1` | The expiry was set. |
| `2` | The time is already in the past, so the field was deleted. |

The errors are the same as for [HEXPIRE](https://docs.hotkv.com/commands/hexpire/index.md): the timestamp
must be a non-negative integer, and one too far in the future gives
``ERR invalid expire time in 'hexpireat' command``.

## Examples

```
127.0.0.1:6379> HSET promo:3 code "SPRING" banner "on"
(integer) 2
127.0.0.1:6379> HEXPIREAT promo:3 1924992000 FIELDS 1 code
1) (integer) 1
127.0.0.1:6379> HEXPIRETIME promo:3 FIELDS 2 code banner
1) (integer) 1924992000
2) (integer) -1
127.0.0.1:6379> HEXPIREAT promo:3 1 FIELDS 1 banner
1) (integer) 2
```

## Compatibility

Same arguments and per-field result codes as Redis 7.4. Valkey 8 does not have
hash field expiration.

## See also

[HEXPIRE](https://docs.hotkv.com/commands/hexpire/index.md), [HPEXPIREAT](https://docs.hotkv.com/commands/hpexpireat/index.md),
[HEXPIRETIME](https://docs.hotkv.com/commands/hexpiretime/index.md), [HPERSIST](https://docs.hotkv.com/commands/hpersist/index.md),
[EXPIREAT](https://docs.hotkv.com/commands/expireat/index.md)