当前位置:网站首页>Redistemplate common collection instructions opsforzset (VI)
Redistemplate common collection instructions opsforzset (VI)
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 opsForZSet() Use of methods :
1、add(K key, V value, double score)
Add the element to the variable and specify the score of the element .
redisTemplate.opsForZSet().add("zSetValue","A",1);
redisTemplate.opsForZSet().add("zSetValue","B",3);
redisTemplate.opsForZSet().add("zSetValue","C",2);
redisTemplate.opsForZSet().add("zSetValue","D",5);
2、range(K key, long start, long end)
Get the element of the specified interval of the variable .
Set zSetValue = redisTemplate.opsForZSet().range("zSetValue",0,-1);
System.out.println(" adopt range(K key, long start, long end) Method to get the element of the specified interval :" + zSetValue);
3、rangeByLex(K key, RedisZSetCommands.Range range)
Used to obtain information that meets the requirements of non - score Sort value of . This sort can only be used if there are the same scores , If there are different scores, the return value is uncertain .
RedisZSetCommands.Range range = new RedisZSetCommands.Range();
//range.gt("A");
range.lt("D");
zSetValue = redisTemplate.opsForZSet().rangeByLex("zSetValue", range);
System.out.println(" adopt rangeByLex(K key, RedisZSetCommands.Range range) Method to obtain a non score Sort value element of :" + zSetValue);
4、rangeByLex(K key, RedisZSetCommands.Range range, RedisZSetCommands.Limit limit)
Used to obtain information that meets the requirements of non - score Set the length sorting value starting from the subscript .
RedisZSetCommands.Limit limit = new RedisZSetCommands.Limit();
limit.count(2);
// Starting subscript is 0
limit.offset(1);
zSetValue = redisTemplate.opsForZSet().rangeByLex("zSetValue", range,limit);
System.out.println(" adopt rangeByLex(K key, RedisZSetCommands.Range range, RedisZSetCommands.Limit limit) Method to obtain a non score Sort value element of :" + zSetValue);
5、add(K key, Set<ZSetOperations.TypedTuple> tuples)
adopt TypedTuple How to add data .
ZSetOperations.TypedTuple<Object> typedTuple1 = new DefaultTypedTuple<Object>("E",6.0);
ZSetOperations.TypedTuple<Object> typedTuple2 = new DefaultTypedTuple<Object>("F",7.0);
ZSetOperations.TypedTuple<Object> typedTuple3 = new DefaultTypedTuple<Object>("G",5.0);
Set<ZSetOperations.TypedTuple<Object>> typedTupleSet = new HashSet<ZSetOperations.TypedTuple<Object>>();
typedTupleSet.add(typedTuple1);
typedTupleSet.add(typedTuple2);
typedTupleSet.add(typedTuple3);
redisTemplate.opsForZSet().add("typedTupleSet",typedTupleSet);
zSetValue = redisTemplate.opsForZSet().range("typedTupleSet",0,-1);
System.out.println(" adopt add(K key, Set<ZSetOperations.TypedTuple<V>> tuples) Method add element :" + zSetValue);
6、rangeByScore(K key, double min, double max)
By setup score Get interval value .
zSetValue = redisTemplate.opsForZSet().rangeByScore("zSetValue",1,2);
System.out.println(" adopt rangeByScore(K key, double min, double max) Method according to the set score Get interval value :" + zSetValue);
7、rangeByScore(K key, double min, double max,long offset, long count)
By setup score Get the interval value and get the final value from the given subscript and given length .
zSetValue = redisTemplate.opsForZSet().rangeByScore("zSetValue",1,5,1,3);
System.out.println(" adopt rangeByScore(K key, double min, double max, long offset, long count) Method according to the set score Get interval value :" + zSetValue);
8、rangeWithScores(K key, long start, long end)
obtain RedisZSetCommands.Tuples The interval value of .
Set<ZSetOperations.TypedTuple<Object>> typedTupleSet = redisTemplate.opsForZSet().rangeWithScores("typedTupleSet",1,3);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = typedTupleSet.iterator();
while (iterator.hasNext()){
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
Object value = typedTuple.getValue();
double score = typedTuple.getScore();
System.out.println(" adopt rangeWithScores(K key, long start, long end) Method to get RedisZSetCommands.Tuples The interval value of :" + value + "---->" + score );
}
9、rangeByScoreWithScores(K key, double min, double max)
obtain RedisZSetCommands.Tuples The interval value of passes through the score .
Set<ZSetOperations.TypedTuple<Object>> typedTupleSet = redisTemplate.opsForZSet().rangeByScoreWithScores("typedTupleSet",5,8);
iterator = typedTupleSet.iterator();
while (iterator.hasNext()){
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
Object value = typedTuple.getValue();
double score = typedTuple.getScore();
System.out.println(" adopt rangeByScoreWithScores(K key, double min, double max) Method to get RedisZSetCommands.Tuples The interval value of passes through the score :" + value + "---->" + score );
}
10、rangeByScoreWithScores(K key, double min, double max, long offset, long count)
obtain RedisZSetCommands.Tuples The interval value of gets the final value from the given subscript and given length through the score .
Set<ZSetOperations.TypedTuple<Object>> typedTupleSet = redisTemplate.opsForZSet().rangeByScoreWithScores("typedTupleSet",5,8,1,1);
iterator = typedTupleSet.iterator();
while (iterator.hasNext()){
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
Object value = typedTuple.getValue();
double score = typedTuple.getScore();
System.out.println(" adopt rangeByScoreWithScores(K key, double min, double max, long offset, long count) Method to get RedisZSetCommands.Tuples The interval value of gets the final value from the given subscript and given length through the score :" + value + "---->" + score );
}
11、count(K key, double min, double max)
Get the number of interval values .
long count = redisTemplate.opsForZSet().count("zSetValue",1,5);
System.out.println(" adopt count(K key, double min, double max) Method to obtain the number of interval values :" + count);
12、rank(K key, Object o)
Get the index of the element in the variable , The starting position of the subscript is 0.
long index = redisTemplate.opsForZSet().rank("zSetValue","B");
System.out.println(" adopt rank(K key, Object o) Method to get the index of the element in the variable :" + index);
13、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<ZSetOperations.TypedTuple<Object>> cursor = redisTemplate.opsForZSet().scan("zSetValue", ScanOptions.NONE);
while (cursor.hasNext()){
ZSetOperations.TypedTuple<Object> typedTuple = cursor.next();
System.out.println(" adopt scan(K key, ScanOptions options) Method to get the matching element :" + typedTuple.getValue() + "--->" + typedTuple.getScore());
}
14、score(K key, Object o)
Get the score of the element .
double score = redisTemplate.opsForZSet().score("zSetValue","B");
System.out.println(" adopt score(K key, Object o) Method to get the score of the element :" + score);
15、zCard(K key)
Get the number of elements in the variable .
long zCard = redisTemplate.opsForZSet().zCard("zSetValue");
System.out.println(" adopt zCard(K key) Method to get the length of the variable :" + zCard);
16、incrementScore(K key, V value, double delta)
Modify the score of the element in the variable .
double incrementScore = redisTemplate.opsForZSet().incrementScore("zSetValue","C",5);
System.out.print(" adopt incrementScore(K key, V value, double delta) Method to modify the score of the element in the variable :" + incrementScore);
score = redisTemplate.opsForZSet().score("zSetValue","C");
System.out.print(", Get the score of the element after modification :" + score);
zSetValue = redisTemplate.opsForZSet().range("zSetValue",0,-1);
System.out.println(", Elements sorted after modification :" + zSetValue);
17、reverseRange(K key, long start, long end)
Arranges the elements of the specified interval in reverse order of the index .
zSetValue = redisTemplate.opsForZSet().reverseRange("zSetValue",0,-1);
System.out.println(" adopt reverseRange(K key, long start, long end) Method to arrange elements in reverse order :" + zSetValue);
18、reverseRangeByScore(K key, double min, double max)
Arrange the elements of the specified score range in reverse order .
zSetValue = redisTemplate.opsForZSet().reverseRangeByScore("zSetValue",1,5);
System.out.println(" adopt reverseRangeByScore(K key, double min, double max) Method to arrange the elements of the specified score interval in reverse order :" + zSetValue);
19、reverseRangeByScore(K key, double min, double max, long offset, long count)
Arrange the elements in reverse order from a given subscript and a given length score interval .
zSetValue = redisTemplate.opsForZSet().reverseRangeByScore("zSetValue",1,5,1,2);
System.out.println(" adopt reverseRangeByScore(K key, double min, double max, long offset, long count) Methods arrange the elements in reverse order from a given subscript and a given length score interval :" + zSetValue);
20、reverseRangeByScoreWithScores(K key, double min, double max)
Sort in reverse order to get RedisZSetCommands.Tuples The score interval value of .
Set<ZSetOperations.TypedTuple<Object>> typedTupleSet = redisTemplate.opsForZSet().reverseRangeByScoreWithScores("zSetValue",1,5);
iterator = typedTupleSet.iterator();
while (iterator.hasNext()){
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
Object value = typedTuple.getValue();
double score1 = typedTuple.getScore();
System.out.println(" adopt reverseRangeByScoreWithScores(K key, double min, double max) Methods reverse order to get RedisZSetCommands.Tuples The interval value of :" + value + "---->" + score1 );
}
21、reverseRangeByScoreWithScores(K key, double min, double max, long offset, long count)
Sort in reverse order to get RedisZSetCommands.Tuples The interval value from a given subscript and a given length score .
Set<ZSetOperations.TypedTuple<Object>> typedTupleSet = redisTemplate.opsForZSet().reverseRangeByScoreWithScores("zSetValue",1,5,1,2);
iterator = typedTupleSet.iterator();
while (iterator.hasNext()){
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
Object value = typedTuple.getValue();
double score1 = typedTuple.getScore();
System.out.println(" adopt reverseRangeByScoreWithScores(K key, double min, double max, long offset, long count) Methods reverse order to get RedisZSetCommands.Tuples From the given subscript and the given length interval value :" + value + "---->" + score1 );
}
22、reverseRangeWithScores(K key, long start, long end)
Index the interval values in reverse order .
Set<ZSetOperations.TypedTuple<Object>> typedTupleSet = redisTemplate.opsForZSet().reverseRangeWithScores("zSetValue",1,5);
iterator = typedTupleSet.iterator();
while (iterator.hasNext()){
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
Object value = typedTuple.getValue();
double score1 = typedTuple.getScore();
System.out.println(" adopt reverseRangeWithScores(K key, long start, long end) Methods index the interval values in reverse order :" + value + "----->" + score1);
}
23、reverseRank(K key, Object o)
Get the index value in reverse order .
long reverseRank = redisTemplate.opsForZSet().reverseRank("zSetValue","B");
System.out.println(" adopt reverseRank(K key, Object o) Get the index value in reverse order :" + reverseRank);
24、intersectAndStore(K key, K otherKey, K destKey)
obtain 2 The intersection of variables is stored in the 3 In a variable .
redisTemplate.opsForZSet().intersectAndStore("zSetValue","typedTupleSet","intersectSet");
zSetValue = redisTemplate.opsForZSet().range("intersectSet",0,-1);
System.out.println(" adopt intersectAndStore(K key, K otherKey, K destKey) Method to get 2 The intersection of variables is stored in the 3 In a variable :" + zSetValue);
25、intersectAndStore(K key, Collection otherKeys, K destKey)
Get the intersection of multiple variables and store it in the 3 In a variable .
List list = new ArrayList();
list.add("typedTupleSet");
redisTemplate.opsForZSet().intersectAndStore("zSetValue",list,"intersectListSet");
zSetValue = redisTemplate.opsForZSet().range("intersectListSet",0,-1);
System.out.println(" adopt intersectAndStore(K key, Collection<K> otherKeys, K destKey) Method to obtain the intersection of multiple variables and store it in the 3 In a variable :" + zSetValue);
26、unionAndStore(K key, K otherKey, K destKey)
obtain 2 The set of variables is stored in the 3 In a variable .
redisTemplate.opsForZSet().unionAndStore("zSetValue","typedTupleSet","unionSet");
zSetValue = redisTemplate.opsForZSet().range("unionSet",0,-1);
System.out.println(" adopt unionAndStore(K key, K otherKey, K destKey) Method to get 2 The intersection of variables is stored in the 3 In a variable :" + zSetValue);
27、unionAndStore(K key, Collection otherKeys, K destKey)
Get the collection of multiple variables and store it in the 3 In a variable .
redisTemplate.opsForZSet().unionAndStore("zSetValue",list,"unionListSet");
zSetValue = redisTemplate.opsForZSet().range("unionListSet",0,-1);
System.out.println(" adopt unionAndStore(K key, Collection<K> otherKeys, K destKey) Method to obtain the intersection of multiple variables and store it in the 3 In a variable :" + zSetValue);
28、remove(K key, Object… values)
Remove elements in batches according to element values .
long removeCount = redisTemplate.opsForZSet().remove("unionListSet","A","B");
zSetValue = redisTemplate.opsForZSet().range("unionListSet",0,-1);
System.out.print(" adopt remove(K key, Object... values) Method to remove the number of elements :" + removeCount);
System.out.println(", The remaining elements after removal :" + zSetValue);
29、removeRangeByScore(K key, double min, double max)
Remove the interval element according to the score .
removeCount = redisTemplate.opsForZSet().removeRangeByScore("unionListSet",3,5);
zSetValue = redisTemplate.opsForZSet().range("unionListSet",0,-1);
System.out.print(" adopt removeRangeByScore(K key, double min, double max) Method to remove the number of elements :" + removeCount);
System.out.println(", The remaining elements after removal :" + zSetValue);
30、removeRange(K key, long start, long end)
Remove the interval element according to the index value .
removeCount = redisTemplate.opsForZSet().removeRange("unionListSet",3,5);
zSetValue = redisTemplate.opsForZSet().range("unionListSet",0,-1);
System.out.print(" adopt removeRange(K key, long start, long end) Method to remove the number of elements :" + removeCount);
System.out.println(", The remaining elements after removal :" + zSetValue);
Here it is ,RedisTemplate.java Class related collection operations are introduced . Students who need to download the source code can download it in the file I uploaded , It can also be in https://github.com/422518490/springRedisTest.git This github Download above , At the same time, the document description is provided in the uploaded file .
边栏推荐
- R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
- 缓存更新策略概览(Caching Strategies Overview)
- OneNote 深度评测:使用资源、插件、模版
- JS学习笔记-OO创建怀疑的对象
- 代理和反向代理
- 在最长的距离二叉树结点
- ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
- 对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
- Interviewer: what is the internal implementation of ordered collection in redis?
- Reinforcement learning - learning notes 5 | alphago
猜你喜欢

Aiko ai Frontier promotion (7.6)

OneNote 深度评测:使用资源、插件、模版

KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
Why does MySQL index fail? When do I use indexes?

967- letter combination of telephone number

【力扣刷题】32. 最长有效括号

互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地

Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces

Aike AI frontier promotion (7.6)

Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
随机推荐
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
在最长的距离二叉树结点
What's the best way to get TFS to output each project to its own directory?
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
Is this the feeling of being spoiled by bytes?
C # use Oracle stored procedure to obtain result set instance
Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]
【论文解读】用于白内障分级/分类的机器学习技术
面试官:Redis中有序集合的内部实现方式是什么?
监控界的最强王者,没有之一!
Yyds dry inventory run kubeedge official example_ Counter demo counter
VIM basic configuration and frequently used commands
互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地
The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
WEB功能测试说明
Manifest of SAP ui5 framework json
Common English vocabulary that every programmer must master (recommended Collection)
b站视频链接快速获取
Proxy and reverse proxy
967- letter combination of telephone number