public static class RedisUtils.SetOps extends Object
| 构造器和说明 |
|---|
SetOps() |
| 限定符和类型 | 方法和说明 |
|---|---|
static long |
sAdd(String key,
Object... items)
向(key对应的)set中添加items
注: 若key不存在,则会自动创建。
|
static Set<Object> |
sDifference(String key,
Collection<String> otherKeys)
获取 (key对应的)Set 减去 (otherKeys对应的)Sets 的差集
注: 如果被减数key不存在, 那么结果为空的集合(,而不是null)
注: 如果被减数key存在,但减数key不存在, 那么结果即为(被减数key对应的)Set
提示: 当有多个减数时, 被减数先减去哪一个减数,后减去哪一个减数,是无所谓的,是不影响最终结果的。
|
static Set<Object> |
sDifference(String key,
String otherKey)
获取 (key对应的)Set 减去 (otherKey对应的)Set 的差集
注: 如果被减数key不存在, 那么结果为空的集合(,而不是null)
注: 如果被减数key存在,但减数key不存在, 那么结果即为(被减数key对应的)Set
|
static long |
sDifferenceAndStore(String key,
Collection<String> otherKeys,
String storeKey)
获取 (key对应的)Set 减去 (otherKey对应的)Set 的差集, 并将结果add到storeKey对应的Set中。
|
static long |
sDifferenceAndStore(String key,
String otherKey,
String storeKey)
获取 (key对应的)Set 减去 (otherKey对应的)Set 的差集, 并将结果add到storeKey对应的Set中。
|
static Set<Object> |
sDistinctRandomMembers(String key,
long count)
从key对应的set中随机获取count个项
注: 若count >= set的size, 那么返回的即为这个key对应的set。
|
static Set<Object> |
sIntersect(String key,
Collection<String> otherKeys)
获取多个(key对应的)Set的交集
注: 若不存在任何交集,那么返回空的集合(, 而不是null)
注: 若>=1个key不存在,那么返回空的集合(, 而不是null)
|
static Set<Object> |
sIntersect(String key,
String otherKey)
获取两个(key对应的)Set的交集
注: 若不存在任何交集,那么返回空的集合(, 而不是null)
注: 若其中一个key不存在(或两个key都不存在),那么返回空的集合(, 而不是null)
|
static long |
sIntersectAndStore(String key,
Collection<String> otherKeys,
String storeKey)
获取多个(key对应的)Set的交集, 并将结果add到storeKey对应的Set中。
|
static long |
sIntersectAndStore(String key,
String otherKey,
String storeKey)
获取两个(key对应的)Set的交集, 并将结果add到storeKey对应的Set中。
|
static boolean |
sIsMember(String key,
Object item)
判断(key对应的)set中是否含有item
注: 若key不存在,则返回false。
|
static Set<Object> |
sMembers(String key)
获取key对应的set
注: 若key不存在, 则返回的是空的set(, 而不是null)
|
static boolean |
sMove(String sourceKey,
String item,
String destinationKey)
将(sourceKey对应的)sourceSet中的元素item, 移动到(destinationKey对应的)destinationSet中
注: 当sourceKey不存在时, 返回false
注: 当item不存在时, 返回false
注: 若destinationKey不存在, 那么在移动时会自动创建
注: 若已经将(sourceKey对应的)set中的项move出去完了,那么对应的sourceKey会被删除。
|
static Object |
sPop(String key)
从(key对应的)set中随机移出一个item, 并返回这个item
注: 因为set是无序的,所以移出的这个item,是随机的; 并且,哪怕
是数据一样的set,多次测试移出操作,移除的元素也是随机的。
|
static Object |
sRandomMember(String key)
从key对应的set中随机获取一项
|
static List<Object> |
sRandomMembers(String key,
long count)
从key对应的set中获取count次随机项(, set中的同一个项可能被多次获取)
注: count可大于set的size。
|
static long |
sRemove(String key,
Object... items)
从(key对应的)set中删除items
注: 若key不存在, 则返回0。
|
static org.springframework.data.redis.core.Cursor<Object> |
sScan(String key,
org.springframework.data.redis.core.ScanOptions options)
根据options匹配到(key对应的)set中的对应的item, 并返回对应的item集
注: ScanOptions实例的创建方式举例:
1、ScanOptions.NONE
2、ScanOptions.scanOptions().match("n??
|
static long |
sSize(String key)
获取(key对应的)set中的元素个数
注: 若key不存在,则返回0
|
static Set<Object> |
sUnion(String key,
Collection<String> otherKeys)
获取两个(key对应的)Set的并集
注: 并集中的元素也是唯一的,这是Set保证的。
|
static Set<Object> |
sUnion(String key,
String otherKey)
获取两个(key对应的)Set的并集
注: 并集中的元素也是唯一的,这是Set保证的。
|
static long |
sUnionAndStore(String key,
Collection<String> otherKeys,
String storeKey)
获取两个(key对应的)Set的并集, 并将结果add到storeKey对应的Set中。
|
static long |
sUnionAndStore(String key,
String otherKey,
String storeKey)
获取两个(key对应的)Set的并集, 并将结果add到storeKey对应的Set中。
|
public static long sAdd(String key, Object... items)
key - 定位set的keyitems - 要向(key对应的)set中添加的itemspublic static long sRemove(String key, Object... items)
key - 定位set的keyitems - 要移除的itemspublic static Object sPop(String key)
key - 定位set的keypublic static boolean sMove(String sourceKey, String item, String destinationKey)
sourceKey - 定位sourceSet的keyitem - 要移动的项目destinationKey - 定位destinationSet的keypublic static long sSize(String key)
key - 定位set的keypublic static boolean sIsMember(String key, Object item)
key - 定位set的keyitem - 被查找的项public static Set<Object> sIntersect(String key, String otherKey)
key - 定位其中一个set的键otherKey - 定位其中另一个set的键public static Set<Object> sIntersect(String key, Collection<String> otherKeys)
key - 定位其中一个set的键otherKeys - 定位其它set的键集public static long sIntersectAndStore(String key, String otherKey, String storeKey)
sIntersect(String, String)key - 定位其中一个set的键otherKey - 定位其中另一个set的键storeKey - 定位(要把交集添加到哪个)set的keypublic static long sIntersectAndStore(String key, Collection<String> otherKeys, String storeKey)
sIntersect(String, Collection)public static Set<Object> sUnion(String key, String otherKey)
key - 定位其中一个set的键otherKey - 定位其中另一个set的键public static Set<Object> sUnion(String key, Collection<String> otherKeys)
key - 定位其中一个set的键otherKeys - 定位其它set的键集public static long sUnionAndStore(String key, String otherKey, String storeKey)
sUnion(String, String)key - 定位其中一个set的键otherKey - 定位其中另一个set的键storeKey - 定位(要把并集添加到哪个)set的keypublic static long sUnionAndStore(String key, Collection<String> otherKeys, String storeKey)
sUnion(String, Collection)key - 定位其中一个set的键otherKeys - 定位其它set的键集storeKey - 定位(要把并集添加到哪个)set的keypublic static Set<Object> sDifference(String key, String otherKey)
key - 定位"被减数set"的键otherKey - 定位"减数set"的键public static Set<Object> sDifference(String key, Collection<String> otherKeys)
key - 定位"被减数set"的键otherKeys - 定位"减数集sets"的键集public static long sDifferenceAndStore(String key, String otherKey, String storeKey)
sDifference(String, String)key - 定位"被减数set"的键otherKey - 定位"减数set"的键storeKey - 定位(要把差集添加到哪个)set的keypublic static long sDifferenceAndStore(String key, Collection<String> otherKeys, String storeKey)
sDifference(String, String)key - 定位"被减数set"的键otherKeys - 定位"减数集sets"的键集storeKey - 定位(要把差集添加到哪个)set的keypublic static Set<Object> sMembers(String key)
key - 定位set的keypublic static Object sRandomMember(String key)
key - 定位set的keypublic static List<Object> sRandomMembers(String key, long count)
key - 定位set的keycount - 要取多少项public static Set<Object> sDistinctRandomMembers(String key, long count)
key - 定位set的keycount - 要取多少项public static org.springframework.data.redis.core.Cursor<Object> sScan(String key, org.springframework.data.redis.core.ScanOptions options)
key - 定位set的keyoptions - 匹配set中的item的条件
注: ScanOptions.NONE表示全部匹配。
注: ScanOptions.scanOptions().match(pattern).build()表示按照pattern匹配,
其中pattern中可以使用通配符 * ? 等,
* 表示>=0个字符
? 表示有且只有一个字符
此处的匹配规则与RedisUtils.KeyOps.keys(String)处的一样。Copyright © 2022. All rights reserved.