*Redis getex 命令

*语法

GETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds |
  PXAT unix-time-milliseconds | PERSIST]

获取 key 的值,并可选择设置其过期时间。 GETEX 类似于 GET,但它是带有附加选项的写命令。

*选项

GETEX 命令支持一组修改其行为的选项:

  • EX seconds -- 设置指定的过期时间,以秒为单位。
  • PX milliseconds -- 设置指定的过期时间,以毫秒为单位。
  • EXAT timestamp-seconds -- 设置键将过期的指定 Unix 时间,以秒为单位。
  • PXAT timestamp-milliseconds -- 设置键将过期的指定 Unix 时间,以毫秒为单位。
  • PERSIST -- 删除与键关联的存活时间。

*示例

redis> SET mykey "Hello"
"OK"
redis> GETEX mykey
ERR Unknown or disabled command 'GETEX'
redis> TTL mykey
(integer) -1
redis> GETEX mykey EX 60
ERR Unknown or disabled command 'GETEX'
redis> TTL mykey
(integer) -1
redis>

*返回信息

RESP2:批量字符串回复: key 的值 Nil 回复: 如果 key 不存在。

RESP3:批量字符串回复: key 的值 Null 回复: 如果 key 不存在。