当前位置:网站首页>Redistemplate common collection instructions opsforset (V)
Redistemplate common collection instructions opsforset (V)
2022-07-06 21:21:00 【Archie_ java】
The basic configuration has been introduced in the previous 《RedisTemplate Instructions for common sets ( One )》 Has been introduced in , Now let's introduce it directly opsForSet() Use of methods :
1、add(K key, V… values)
Batch add values to variables .
redisTemplate.opsForSet().add("setValue","A","B","C","B","D","E","F");
2、members(K key)
Get the value in the variable .
Set set = redisTemplate.opsForSet().members("setValue");
System.out.println(" adopt members(K key) Method to get the element value in the variable :" + set);
3、size(K key)
Get the length of the value of the variable .
long setLength = redisTemplate.opsForSet().size("setValue");
System.out.println(" adopt size(K key) Method to get the length of the element value in the variable :" + setLength);
4、randomMember(K key)
Get the elements in the variable at random .
Object randomMember = redisTemplate.opsForSet().randomMember("setValue");
System.out.println(" adopt randomMember(K key) Method to randomly obtain the elements in the variable :" + randomMember);
5、randomMembers(K key, long count)
Randomly get the specified number of elements in the variable .
List randomMembers = redisTemplate.opsForSet().randomMembers("setValue",2);
System.out.println(" adopt randomMembers(K key, long count) Method to randomly obtain the specified number of elements in the variable :" + randomMembers);
6、isMember(K key, Object o)
Check whether the given element is in a variable .
boolean isMember = redisTemplate.opsForSet().isMember("setValue","A");
System.out.println(" adopt isMember(K key, Object o) Method to check whether a given element is in a variable :" + isMember);
7、move(K key, V value, K destKey)
Transfer element value of variable to destination variable .
boolean isMove = redisTemplate.opsForSet().move("setValue","A","destSetValue");
if(isMove){
set = redisTemplate.opsForSet().members("setValue");
System.out.print(" adopt move(K key, V value, K destKey) Method transfers the element value of the variable to the remaining element after the destination variable :" + set);
set = redisTemplate.opsForSet().members("destSetValue");
System.out.println(", The element value in the destination variable :" + set);
}
8、pop(K key)
Pop up elements in variables .
Object popValue = redisTemplate.opsForSet().pop("setValue");
System.out.print(" adopt pop(K key) Method to pop up the element in the variable :" + popValue);
set = redisTemplate.opsForSet().members("setValue");
System.out.println(", The remaining elements :" + set)
9、remove(K key, Object… values)
Remove the element in the batch .
long removeCount = redisTemplate.opsForSet().remove("setValue","E","F","G");
System.out.print(" adopt remove(K key, Object... values) Method to remove the number of elements in the variable :" + removeCount);
set = redisTemplate.opsForSet().members("setValue");
System.out.println(", The remaining elements :" + set);
10、scan(K key, ScanOptions options)
Match to get key value pairs ,ScanOptions.NONE To get all key value pairs ;ScanOptions.scanOptions().match(“C”).build() Match to get the key map1 The key/value pair , No fuzzy matching .
//Cursor<Object> cursor = redisTemplate.opsForSet().scan("setValue", ScanOptions.NONE);
Cursor<Object> cursor = redisTemplate.opsForSet().scan("setValue", ScanOptions.scanOptions().match("C").build());
while (cursor.hasNext()){
Object object = cursor.next();
System.out.println(" adopt scan(K key, ScanOptions options) Method to get the matching value :" + object);
}
11、difference(K key, Collection otherKeys)
Find the difference through the set .
List list = new ArrayList();
list.add("destSetValue");
Set differenceSet = redisTemplate.opsForSet().difference("setValue",list);
System.out.println(" adopt difference(K key, Collection<K> otherKeys) Method to get the value in the variable that is different from the variable in the given set :" + differenceSet);
12、difference(K key, K otherKey)
By giving key seek 2 individual set The difference between variables .
differenceSet = redisTemplate.opsForSet().difference("setValue","destSetValue");
System.out.println(" adopt difference(K key, Collection<K> otherKeys) Method to get the value in the variable that is different from the given variable :" + differenceSet);
13、differenceAndStore(K key, K otherKey, K destKey)
Save the calculated difference element .
redisTemplate.opsForSet().differenceAndStore("setValue","destSetValue","storeSetValue");
set = redisTemplate.opsForSet().members("storeSetValue");
System.out.println(" adopt differenceAndStore(K key, K otherKey, K destKey) Method to save the calculated difference element :" + set);
14、differenceAndStore(K key, Collection otherKeys, K destKey)
Save the calculated difference element .
redisTemplate.opsForSet().differenceAndStore("setValue",list,"storeSetValue");
set = redisTemplate.opsForSet().members("storeSetValue");
System.out.println(" adopt differenceAndStore(K key, Collection<K> otherKeys, K destKey) Method to save the calculated difference element :" + set);
15、distinctRandomMembers(K key, long count)
Get the random element of de duplication .
set = redisTemplate.opsForSet().distinctRandomMembers("setValue",2);
System.out.println(" adopt distinctRandomMembers(K key, long count) Method to get the random element of the de duplication :" + set);
16、intersect(K key, K otherKey)
obtain 2 Intersection of variables .
set = redisTemplate.opsForSet().intersect("setValue","destSetValue");
System.out.println(" adopt intersect(K key, K otherKey) Method to get the intersection element :" + set);
17、intersect(K key, Collection otherKeys)
Get the intersection between multiple variables .
set = redisTemplate.opsForSet().intersect("setValue",list);
System.out.println(" adopt intersect(K key, Collection<K> otherKeys) Method to get the intersection element :" + set);
18、intersectAndStore(K key, K otherKey, K destKey)
obtain 2 Save the intersection of variables to the last parameter .
redisTemplate.opsForSet().intersectAndStore("setValue","destSetValue","intersectValue");
set = redisTemplate.opsForSet().members("intersectValue");
System.out.println(" adopt intersectAndStore(K key, K otherKey, K destKey) Method to save the intersection elements :" + set);
19、intersectAndStore(K key, Collection otherKeys, K destKey)
Get the intersection of multiple variables and save it to the last parameter .
redisTemplate.opsForSet().intersectAndStore("setValue",list,"intersectListValue");
set = redisTemplate.opsForSet().members("intersectListValue");
System.out.println(" adopt intersectAndStore(K key, Collection<K> otherKeys, K destKey) Method to save the intersection elements :" + set);
20、union(K key, K otherKey)
obtain 2 A collection of variables .
set = redisTemplate.opsForSet().union("setValue","destSetValue");
System.out.println(" adopt union(K key, K otherKey) Method to get 2 A collection of variables :" + set);
21、union(K key, Collection otherKeys)
Get the collection of multiple variables .
set = redisTemplate.opsForSet().union("setValue",list);
System.out.println(" adopt union(K key, Collection<K> otherKeys) Method to obtain the collection element of multiple variables :" + set);
22、unionAndStore(K key, K otherKey, K destKey)
obtain 2 Save the set of variables to the last parameter .
redisTemplate.opsForSet().unionAndStore("setValue","destSetValue","unionValue");
set = redisTemplate.opsForSet().members("unionValue");
System.out.println(" adopt unionAndStore(K key, K otherKey, K destKey) Method to save the intersection elements :" + set);
23、unionAndStore(K key, Collection otherKeys, K destKey)
Get the collection of multiple variables and save it to the last parameter .
redisTemplate.opsForSet().unionAndStore("setValue",list,"unionListValue");
set = redisTemplate.opsForSet().members("unionListValue");
System.out.println(" adopt unionAndStore(K key, Collection<K> otherKeys, K destKey) Method to save the intersection elements :" + set);
边栏推荐
- The most comprehensive new database in the whole network, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, flying Book Multidimensional table, heipayun, Zhix
- FZU 1686 龙之谜 重复覆盖
- Common English vocabulary that every programmer must master (recommended Collection)
- Web开发小妙招:巧用ThreadLocal规避层层传值
- Why does MySQL index fail? When do I use indexes?
- Acdreamoj1110 (multiple backpacks)
- b站视频链接快速获取
- Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
- 038. (2.7) less anxiety
- R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
猜你喜欢

Aiko ai Frontier promotion (7.6)

审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?

Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"

愛可可AI前沿推介(7.6)

Fastjson parses JSON strings (deserialized to list, map)

SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍

SAP UI5 框架的 manifest.json

LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件

20220211 failure - maximum amount of data supported by mongodb
Why does MySQL index fail? When do I use indexes?
随机推荐
Technology sharing | packet capturing analysis TCP protocol
ICML 2022 | flowformer: task generic linear complexity transformer
Is it profitable to host an Olympic Games?
for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
c#使用oracle存储过程获取结果集实例
通过数字电视通过宽带网络取代互联网电视机顶盒应用
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
document.write()的用法-写入文本——修改样式、位置控制
Yyds dry inventory run kubeedge official example_ Counter demo counter
Nodejs tutorial let's create your first expressjs application with typescript
20220211 failure - maximum amount of data supported by mongodb
OAI 5g nr+usrp b210 installation and construction
Caching strategies overview
It's almost the new year, and my heart is lazy
Reinforcement learning - learning notes 5 | alphago
字符串的使用方法之startwith()-以XX开头、endsWith()-以XX结尾、trim()-删除两端空格
防火墙基础之外网服务器区部署和双机热备
【mysql】触发器
2017 8th Blue Bridge Cup group a provincial tournament
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”