# GETEX Get the value of `key` and optionally set its expiration. `GETEX` is similar to [`GET`](https://redis.io/docs/latest/commands/get), but is a write command with additional options. ## Options The `GETEX` command supports a set of options that modify its behavior: * `EX` *seconds* -- Set the specified expire time, in seconds. * `PX` *milliseconds* -- Set the specified expire time, in milliseconds. * `EXAT` *timestamp-seconds* -- Set the specified Unix time at which the key will expire, in seconds. * `PXAT` *timestamp-milliseconds* -- Set the specified Unix time at which the key will expire, in milliseconds. * [`PERSIST`](https://redis.io/docs/latest/commands/persist) -- Remove the time to live associated with the key. ## Examples SET mykey "Hello" GETEX mykey TTL mykey GETEX mykey EX 60 TTL mykey ## Return information {{< multitabs id="getex-return-info" tab1="RESP2" tab2="RESP3" >}} [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the value of `key` [Nil reply](../../develop/reference/protocol-spec#bulk-strings): if `key` does not exist. -tab-sep- [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the value of `key` [Null reply](../../develop/reference/protocol-spec#nulls): if `key` does not exist.