# HPEXPIREAT

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

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

```
HPEXPIREAT key unix-time-milliseconds [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

`HPEXPIREAT` works like [HEXPIREAT](https://docs.hotkv.com/commands/hexpireat/index.md), but the timestamp
is in milliseconds since the Unix epoch. A timestamp 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); a timestamp too
far in the future gives ``ERR invalid expire time in 'hpexpireat' command``.

## Examples

```
127.0.0.1:6379> HSET promo:3 code "SPRING"
(integer) 1
127.0.0.1:6379> HPEXPIREAT promo:3 1924992000500 FIELDS 1 code
1) (integer) 1
127.0.0.1:6379> HPEXPIRETIME promo:3 FIELDS 1 code
1) (integer) 1924992000500
```

## Compatibility

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

## See also

[HEXPIREAT](https://docs.hotkv.com/commands/hexpireat/index.md), [HPEXPIRE](https://docs.hotkv.com/commands/hpexpire/index.md),
[HPEXPIRETIME](https://docs.hotkv.com/commands/hpexpiretime/index.md), [HPERSIST](https://docs.hotkv.com/commands/hpersist/index.md),
[PEXPIREAT](https://docs.hotkv.com/commands/pexpireat/index.md)