GETEX

Syntax
GETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds |
  PXAT unix-time-milliseconds | PERSIST]
Available since:
6.2.0
Time complexity:
O(1)
ACL categories:
@write, @string, @fast,

获取key的值并可选地设置其过期时间。 GETEX类似于GET,但是一个带有额外选项的写入命令。

选项

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

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

示例

SET mykey "Hello" GETEX mykey TTL mykey GETEX mykey EX 60 TTL mykey

RESP2 回复

Bulk string reply: the value of key Nil reply: if key does not exist.

RESP3 回复

Bulk string reply: the value of key Null reply: if key does not exist.
RATE THIS PAGE
Back to top ↑