Redis sets redis集合

Title: Redis sets
date: 2015-05-05 12:08:36 +0800
comments: true
category: Redis
tags: redis,linux

Redis Sets

## SADD -- add item into set
    SADD myset "James"
    # if success, return 1, else return 0

## SMEMBERS -- check members in set
    SMEMBERS myset

## SREM -- delete members from set
    SREM myset "Harry"
    # if delete, return 1, else return 0, e.g. delete an un-exist member

## SPOP -- return and delete one key by random in set
    SPOP myset

## SDIFF -- 返回所有给定的key与第一个key的差集
    SDIFF set1 set2
    # return member only in set1 and not in set2

## SDIFFSTORE -- 返回所有给定的key与第一个key的差集, 并将结果保存为另一个key
    SDIFFSTORE result-set set1 set2
    SMEMBERS result-set

## SINTER -- 返回所有给定的key的交集
    SINTER set1 set2 [set3 ... setN]

## SINTERSTORE -- 交集结果保存为另一个set
    SINTERSTORE result-set set1 set2 [set3 ... setN]

## SUNION -- 并集
    SUNION set1 set2 [set3 ... setN]

## SUNIONSTORE -- 并集结果保存到另一个set
    SUNIONSTORE result-set set1 set2 [set3 ... setN]

## SMOVE -- 从第一个key对应的set中移除member并添加到第二个对应set中
    SMOVE first-set result-set member-name
        127.0.0.1:6379[8]> SMEMBERS t_num2
        1) "five"
        2) "three"
        3) "one"
        127.0.0.1:6379[8]> SMOVE t_num2 t_num4 five
        (integer) 1
        127.0.0.1:6379[8]> SMEMBERS t_num2
        1) "three"
        2) "one"
        127.0.0.1:6379[8]> SMEMBERS t_num4
        1) "five"
## SCARD -- return number of the set
    SCARD myset

## SINMEMBER -- test if member is in set
    SINMEMBER myset member-name

## SRANDMEMBER -- 随机返回名称为key的set的一个元素,但是不删除元素
    SRANDMEMBER myset

你可能感兴趣的:(Redis sets redis集合)