# NEXPIRE

> Set a key's time to live in nanoseconds.

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

```
NEXPIRE key nanoseconds
```

- Group: Keys
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`NEXPIRE` makes `key` expire after the given number of nanoseconds. Use it
when millisecond precision ([PEXPIRE](https://docs.hotkv.com/commands/pexpire/index.md)) is too coarse, for
example for very short-lived locks or sub-millisecond rate windows. Read the
remaining time back with [NTTL](https://docs.hotkv.com/commands/nttl/index.md).

`NEXPIRE` takes no `NX`, `XX`, `GT` or `LT` options: it always replaces the
key's current time to live. A value of zero or less makes the key expire at
once (the reply is still `1`).

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| The time was set | Integer `1` | Integer `1` |
| The key does not exist | Integer `0` | Integer `0` |

`ERR value is not an integer or out of range` when `nanoseconds` is not a
64-bit integer.

## Examples

```
127.0.0.1:6379> SET lease "worker-3"
OK
127.0.0.1:6379> NEXPIRE lease 250000000
(integer) 1
127.0.0.1:6379> PTTL lease
(integer) 249
127.0.0.1:6379> NEXPIRE missing 1000
(integer) 0
```

## Compatibility

HotKV-only command. Unlike [EXPIRE](https://docs.hotkv.com/commands/expire/index.md), it does not publish an
`expire` keyspace event.

## See also

[NEXPIREAT](https://docs.hotkv.com/commands/nexpireat/index.md), [NTTL](https://docs.hotkv.com/commands/nttl/index.md),
[PEXPIRE](https://docs.hotkv.com/commands/pexpire/index.md), [EXPIRE](https://docs.hotkv.com/commands/expire/index.md)