Redis Getset 命令

更新时间: 2019-07-07 15:54

Redis Getset 命令用于设置指定 key 的值,并返回 key 的旧值。

语法

redis 127.0.0.1:6379> GETSET KEY_NAME VALUE

返回值

返回给定 key 的旧值。 当 key 没有旧值时,即 key 不存在时,返回 nil 。

当 key 存在但不是字符串类型时,返回一个错误。

实例

实例1: key 存在,且是字符串类型

127.0.0.1:6379> get domain
"www.codercto.com"
127.0.0.1:6379> getset domain "www.codercto.com_new"
"www.codercto.com"
127.0.0.1:6379> get domain
"www.codercto.com_new"

实例2: key 存在, 但不是字符串类型

127.0.0.1:6379> lpush domain "www.codercto.com"
(integer) 1
127.0.0.1:6379> getset domain "www.codercto.com_new"
(error) WRONGTYPE Operation against a key holding the wrong kind of value

实例2: key 不存在

127.0.0.1:6379> exists domain
(integer) 0
127.0.0.1:6379> getset domain "www.codercto.com_new"
(nil)

查看更多 Redis 字符串(String)命令

Tales from Facebook

Tales from Facebook

Daniel Miller / Polity Press / 2011-4-1 / GBP 55.00

Facebook is now used by nearly 500 million people throughout the world, many of whom spend several hours a day on this site. Once the preserve of youth, the largest increase in usage today is amongst ......一起来看看 《Tales from Facebook》 这本书的介绍吧!

HTML 压缩/解压工具

HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB HSV 转换

RGB HSV 转换

RGB HSV 互转工具

HEX HSV 转换工具

HEX HSV 转换工具

HEX HSV 互换工具