修改本页

Redis 命令 客户端 文档 社区 下载 问题 支持 许可

SETEX key seconds value

相关命令

Available since 2.0.0.

时间复杂度: O(1)

Set key to hold the string value and set key to timeout after a given number of seconds. This command is equivalent to executing the following commands:

  1. SET mykey value
  2. EXPIRE mykey seconds

SETEX is atomic, and can be reproduced by using the previous two commands inside an MULTI / EXEC block. It is provided as a faster alternative to the given sequence of operations, because this operation is very common when Redis is used as a cache.

An error is returned when seconds is invalid.

返回值

Simple string reply

例子

redis> SETEX mykey 10 "Hello"

  1. OK

redis> TTL mykey

  1. (integer) 10

redis> GET mykey

  1. "Hello"
redis>

Comments powered by Disqus

This website is open source software developed by Citrusbyte.

The Redis logo was designed by Carlos Prioglio. See more credits.

Sponsored by Redis Support