Redis Setnx 命令

Redis 教程 · 2019-03-06 23:43:38

Redis Setnx(SET if Not eXists) 命令在指定的 key 不存在时,为 key 设置指定的值。

语法

redis Setnx 命令基本语法如下:

redis 127.0.0.1:6379> SETNX KEY_NAME VALUE

可用版本

>= 1.0.0

返回值

设置成功,返回 1 。 设置失败,返回 0 。

实例

redis> EXISTS job                # job 不存在
(integer) 0

redis> SETNX job "programmer"    # job 设置成功
(integer) 1

redis> SETNX job "code-farmer"   # 尝试覆盖 job ,失败
(integer) 0

redis> GET job                   # 没有被覆盖
"programmer"

点击查看所有 Redis 教程 文章: https://www.codercto.com/courses/l/33.html

查看所有标签

Struts 2 in Action

Struts 2 in Action

Don Brown、Chad Davis、Scott Stanlick / Manning Publications / 2008.3 / $44.99

The original Struts project revolutionized Java web development and its rapid adoption resulted in the thousands of Struts-based applications deployed worldwide. Keeping pace with new ideas and trends......一起来看看 《Struts 2 in Action》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码