1.插入數(shù)據(jù)
sadd key value1 value2 value3
集合的數(shù)據(jù)是唯一的,插入之后再次插入時(shí)不會(huì)執(zhí)行
2.讀取數(shù)據(jù)
(1)查詢集合里面元素的數(shù)量
scard key
(2)從集合中獲取數(shù)據(jù)
spop key count
--如果count省略則隨機(jī)獲取一條數(shù)據(jù)
--如果count為其他大于1的整數(shù),則獲取對應(yīng)條數(shù)據(jù)
--如果count對應(yīng)的證書大于集合總數(shù)據(jù)的條數(shù),則獲取集合所有數(shù)據(jù)
(3)獲取集合中的所有數(shù)據(jù)
smembers key
(4)判斷集合中是否存在某個(gè)元素
sismember key value
--如果數(shù)據(jù)存在,則返回1,如果數(shù)據(jù)不存在,則返回0
3.刪除數(shù)據(jù)
srem key value1 value2 value3
4.集合的交集
既屬于A集合又屬于B/其他集合,集合數(shù)量可以是多個(gè),多個(gè)代表對應(yīng)所有集合的交集
sinter key1 key2 key3
5.集合的并集
A集合與B/其他集合所包含的所有數(shù)據(jù),如果數(shù)據(jù)一樣則去重,集合數(shù)量可以是多個(gè),多個(gè)代表對應(yīng)所有集合的并集
sunion key1 key2 key3
6.集合的差集
只屬于A(key1)集合,不屬于其他集合的數(shù)據(jù)
sdiff key1 key2 key3