# PSETEX

> Set a string value with a time to live in milliseconds.

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

```
PSETEX key milliseconds value
```

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

`PSETEX` stores `value` at `key` and makes it expire after `milliseconds`, in
one step. It is the same as `SET key value PX milliseconds`.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Always | Simple string `OK` | Simple string `OK` |

Errors:

- `ERR value is not an integer or out of range` when `milliseconds` is not an
  integer.
- `ERR invalid expire time in 'psetex' command` when `milliseconds` is zero,
  negative or too large.

## Examples

```
127.0.0.1:6379> PSETEX lock:job 1500 "worker-2"
OK
127.0.0.1:6379> PTTL lock:job
(integer) 1500
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[SET](https://docs.hotkv.com/commands/set/index.md), [SETEX](https://docs.hotkv.com/commands/setex/index.md),
[PEXPIRE](https://docs.hotkv.com/commands/pexpire/index.md)