Redis Sadd 命令

Redis 教程 · 2019-03-07 16:13:20

Redis Sadd 命令将一个或多个成员元素加入到集合中,已经存在于集合的成员元素将被忽略。

假如集合 key 不存在,则创建一个只包含添加的元素作成员的集合。

当集合 key 不是集合类型时,返回一个错误。

注意:在Redis2.4版本以前, SADD 只接受单个成员值。

语法

redis Sadd 命令基本语法如下:

redis 127.0.0.1:6379> SADD KEY_NAME VALUE1..VALUEN

可用版本

>= 1.0.0

返回值

被添加到集合中的新元素的数量,不包括被忽略的元素。

实例

redis 127.0.0.1:6379> SADD myset "hello"
(integer) 1
redis 127.0.0.1:6379> SADD myset "foo"
(integer) 1
redis 127.0.0.1:6379> SADD myset "hello"
(integer) 0
redis 127.0.0.1:6379> SMEMBERS myset
1) "hello"
2) "foo"

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

查看所有标签

The Little Schemer - 4th Edition

The Little Schemer - 4th Edition

Daniel P. Friedman、Matthias Felleisen / The MIT Press / 1995-12-21 / USD 40.00

This delightful book leads you through the basic elements of programming in Scheme (a Lisp dialect) via a series of dialogues with well-chosen questions and exercises. Besides teaching Scheme, The Lit......一起来看看 《The Little Schemer - 4th Edition》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具