Options
The SET command supports a set of options that modify its behavior:
EXseconds — Set the specified expire time, in seconds.设置指定的过期时间,单位为秒。PXmilliseconds — Set the specified expire time, in milliseconds.设置指定的过期时间,单位为毫秒。EXATtimestamp-seconds — Set the specified Unix time at which the key will expire, in seconds.设置密钥过期的指定Unix时间,以秒为单位。PXATtimestamp-milliseconds — Set the specified Unix time at which the key will expire, in milliseconds.设置键过期的指定Unix时间,以毫秒为单位。NX— Only set the key if it does not already exist.只在键不存在的情况下设置它。XX— Only set the key if it already exist.只有在键已经存在时才设置它。KEEPTTL— Retain the time to live associated with the key.保留之前设置的过期时间。GET— Return the old string stored at key, or nil if key did not exist. An error is returned and SET aborted if the value stored at key is not a string. 返回存储在key处的旧字符串,如果key不存在则返回nil。如果存储在key处的值不是字符串,则返回错误并终止SET。
Note: Since the SET command options can replace SETNX, SETEX, PSETEX, GETSET, it is possible that in future versions of Redis these commands will be deprecated and finally removed.
注意:由于SET命令选项可以替代SETNX, SETEX, PSETEX, GETSET,在未来的Redis版本中,这些命令可能会被弃用并最终被删除。
Examples
redis> SET mykey “Hello”
“OK”
redis> GET mykey
“Hello”
redis> SET anotherkey “will expire in a minute” EX 60
“OK”
redis>
The command SET resource-name anystring NX EX max-lock-time is a simple way to implement a locking system with Redis.
命令 SET resource-name anystring NX EX max-lock-time 是Redis实现锁定系统的一种简单方法。