当前位置:网站首页>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 .
边栏推荐
- Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
- MySQL - 事务(Transaction)详解
- 监控界的最强王者,没有之一!
- R3live notes: image processing section
- SDL2来源分析7:演出(SDL_RenderPresent())
- 分糖果
- Technology sharing | packet capturing analysis TCP protocol
- 互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地
- 2022 fields Award Announced! The first Korean Xu Long'er was on the list, and four post-80s women won the prize. Ukrainian female mathematicians became the only two women to win the prize in history
- Nodejs tutorial expressjs article quick start
猜你喜欢
Swagger UI tutorial API document artifact
互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地
Absolute primes (C language)
Is it profitable to host an Olympic Games?
[MySQL] basic use of cursor
Aiko ai Frontier promotion (7.6)
Why do job hopping take more than promotion?
嵌入式开发的7大原罪
基于深度学习的参考帧生成
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
随机推荐
【论文解读】用于白内障分级/分类的机器学习技术
Acdreamoj1110 (multiple backpacks)
What is the problem with the SQL group by statement
b站视频链接快速获取
14年本科毕业,转行软件测试,薪资13.5K
Ravendb starts -- document metadata
技术分享 | 抓包分析 TCP 协议
快过年了,心也懒了
Interviewer: what is the internal implementation of ordered collection in redis?
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
Aiko ai Frontier promotion (7.6)
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
Notes - detailed steps of training, testing and verification of yolo-v4-tiny source code
JS traversal array and string
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
El table table - get the row and column you click & the sort of El table and sort change, El table column and sort method & clear sort clearsort
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
Thinking about agile development
Vim 基本配置和经常使用的命令