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)命令

The Four

The Four

Scott Galloway / Portfolio / 2017-10-3 / USD 28.00

NEW YORK TIMES BESTSELLER USA TODAY BESTSELLER Amazon, Apple, Facebook, and Google are the four most influential companies on the planet. Just about everyone thinks they know how they got there.......一起来看看 《The Four》 这本书的介绍吧!

JS 压缩/解压工具

JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具

CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB CMYK 转换工具

RGB CMYK 转换工具

RGB CMYK 互转工具