您的位置:首页 > 数据库 > Redis

4、使用SetOperations(无序)操作redis(Set集合)

2021-11-23 22:17 986 查看

文章来源:https://www.cnblogs.com/shiguotao-com/p/10560599.html

方法 c参数 s说明
Long add(K key, V... values);
K key:集合key
V... values:key对应的值
向集合中添加一个或多一个元素
Long remove(K key, Object... values);
K key:集合key
V... values:key对应的值
删除集合中一个或多个元素
V pop(K key);
 
K key:集合key
随机删除集合中一个元素
List<V> pop(K key, long count);
K key:集合key
long count:数量
随机删除集合中一个或多个元素
Boolean move(K key, V value, K destKey);
K key:集合key
V value:key对应的某个值
K destKey:目标集合
将某一个集合中的元素移动到目标集合中
Long size(K key);
K key:集合key
获取集合长度
Boolean isMember(K key, Object o);
K key:集合key
V value:key对应的某个值
检查集合中是否存在某个元素
Set<V> intersect(K key, K otherKey);
K key:集合A的key
K otherKey:集合B的key
获取集合A和集合B的交集
Set<V> intersect(K key, Collection<K> otherKeys);
 
K key:集合A的key
Collection<K> otherKeys:其他集合的集合(可多个)
 获取集合A和其他的交集
 
Long intersectAndStore(K key, K otherKey, K destKey);
 
K key:集合A的key
K otherKey:集合B的key
K destKey:集合C的key
 将集合A和集合B的交集存放到集合C中
 
Long intersectAndStore(K key, Collection<K> otherKeys, K destKey);
 
K key:集合A的key
Collection<K> otherKeys:其他集合的key(可多个)
K destKey:集合C的key
 将集合A和其他集合的交集存放到集合C中
 
Set<V> union(K key, K otherKey);
 
K key:集合A的key
K otherKey:集合B的key
 获取集合A和集合B集合合并后的集合
 
Set<V> union(K key, Collection<K> otherKeys);
 
K key:集合A的key
Collection<K> otherKeys:其他集合的key(可多个)
 获取集合A和其他集合(多个)合并后的集合
 
Long unionAndStore(K key, K otherKey, K destKey);
 
K key:集合A的key
K otherKey:集合B的key
K destKey:集合C的key
 将集合A和集合B合并后的结果存放到集合C中
 
Long unionAndStore(K key, Collection<K> otherKeys, K destKey);
 
K key:集合A的key
Collection<K> otherKeys:其他集合的key(可多个)
K destKey:集合C的key
 将集合A和其他集合合并后的结果存放到集合C中
 
Set<V> difference(K key, K otherKey);
 
K key:集合A的key
K otherKey:集合B的key
 获取集合A和集合B的差集
 
Set<V> difference(K key, Collection<K> otherKeys);
 
K key:集合A的key
Collection<K> otherKeys:其他集合的key(可多个)
 获取集合A和其他集合的差集
 
Long differenceAndStore(K key, K otherKey, K destKey);
 
K key:集合A的key
K otherKey:集合B的key
K destKey:集合C的key
 将集合A和集合B的差集存放到集合C中
 
Long differenceAndStore(K key, Collection<K> otherKeys, K destKey);
 
K key:集合A的key
Collection<K> otherKeys:其他集合的key(可多个)
K destKey:集合C的key
  将集合A和其他集合的差集存放到集合C中
 
Set<V> members(K key);
 
K key:集合A的key
 获取集合中的多有元素
 
V randomMember(K key);
 
K key:集合A的key
 在集合中随机获取一个元素
 
Set<V> distinctRandomMembers(K key, long count);
 
K key:集合A的key
count:数量
 在集合中随机获取count个不同的元素
 
List<V> randomMembers(K key, long count);
 
K key:集合A的key
count:数量
 在集合中随机获取count个元素
 
Cursor<V> scan(K key, ScanOptions options);
 
K key:集合A的key
ScanOptions options:扫描选项对象
 扫描整个集合一匹配所需元素
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: