当前位置:网站首页>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 .
边栏推荐
- document. Usage of write () - write text - modify style and position control
- 2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
- What are RDB and AOF
- 缓存更新策略概览(Caching Strategies Overview)
- 袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
- Forward maximum matching method
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- WEB功能测试说明
- Deployment of external server area and dual machine hot standby of firewall Foundation
- Pat 1078 hashing (25 points) ⼆ times ⽅ exploration method
猜你喜欢

SAP UI5 框架的 manifest.json

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

Study notes of grain Mall - phase I: Project Introduction

Summary of cross partition scheme

The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop

MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.

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

Deployment of external server area and dual machine hot standby of firewall Foundation

Why do job hopping take more than promotion?

20220211 failure - maximum amount of data supported by mongodb
随机推荐
Yyds dry inventory run kubeedge official example_ Counter demo counter
js之遍历数组、字符串
面试官:Redis中有序集合的内部实现方式是什么?
Seven original sins of embedded development
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
The biggest pain point of traffic management - the resource utilization rate cannot go up
Mtcnn face detection
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
【mysql】触发器
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
ACdreamoj1110(多重背包)
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
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
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
基于深度学习的参考帧生成
for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
Description of web function test
document. Usage of write () - write text - modify style and position control
【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug