当前位置:网站首页>Redistemplate common collection instructions opsforlist (III)
Redistemplate common collection instructions opsforlist (III)
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 opsForList() Use of methods :
1、leftPush(K key, V value)
Add the element value to the left of the variable .
redisTemplate.opsForList().leftPush("list","a");
redisTemplate.opsForList().leftPush("list","b");
redisTemplate.opsForList().leftPush("list","c");
2、index(K key, long index)
Gets the value of the specified location in the collection .
String listValue = redisTemplate.opsForList().index("list",1) + "";
System.out.println(" adopt index(K key, long index) Method to get the value of the specified location :" + listValue);
3、range(K key, long start, long end)
Get the value of the specified interval .
List<Object> list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt range(K key, long start, long end) Method to get the collection value of the specified range :"+list);
4、leftPush(K key, V pivot, V value)
Place the last parameter value before the first intermediate parameter in the specified set , If an intermediate parameter value exists .
redisTemplate.opsForList().leftPush("list","a","n");
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt leftPush(K key, V pivot, V value) Method to put the value in front of the specified parameter value :" + list);
5、leftPushAll(K key, V… values)
Batch add parameter elements to the left .
redisTemplate.opsForList().leftPushAll("list","w","x","y");
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt leftPushAll(K key, V... values) Method to batch add elements :" + list);
6、leftPushAll(K key, Collection values)
Batch add elements to the left as a collection .
List newList = new ArrayList();
newList.add("o");
newList.add("p");
newList.add("q");
redisTemplate.opsForList().leftPushAll("list",newList);
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt leftPushAll(K key, Collection<V> values) Method to batch add elements in the form of a collection :" + list);
7、leftPushIfPresent(K key, V value)
If there is a collection, add the element .
redisTemplate.opsForList().leftPushIfPresent("presentList","o");
list = redisTemplate.opsForList().range("presentList",0,-1);
System.out.println(" adopt leftPushIfPresent(K key, V value) Method to add elements to an existing collection :" + list);
8、rightPush(K key, V value)
Add elements to the far right of the collection .
redisTemplate.opsForList().rightPush("list","w");
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt rightPush(K key, V value) Method to add an element to the far right :" + list);
9、rightPush(K key, V pivot, V value)
Add the element value of the third parameter variable to the right of the second parameter variable element in the set for the first time .
redisTemplate.opsForList().rightPush("list","w","r");
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt rightPush(K key, V pivot, V value) Method to add an element to the far right :" + list);
10、rightPushAll(K key, V… values)
Batch add elements to the right .
redisTemplate.opsForList().rightPushAll("list","j","k");
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt rightPushAll(K key, V... values) Method to batch add elements to the far right :" + list);
11、rightPushAll(K key, Collection values)
Add elements to the right as a collection .
newList.clear();
newList.add("g");
newList.add("h");
redisTemplate.opsForList().rightPushAll("list",newList);
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt rightPushAll(K key, Collection<V> values) Method to batch add elements to the far right in a collection :" + list);
12、rightPushIfPresent(K key, V value)
Add elements to an existing collection .
redisTemplate.opsForList().rightPushIfPresent("presentList","d");
list = redisTemplate.opsForList().range("presentList",0,-1);
System.out.println(" adopt rightPushIfPresent(K key, V value) Method adds elements to the rightmost side of the existing collection :" + list);
13、size(K key)
Get collection length .
long listLength = redisTemplate.opsForList().size("list");
System.out.println(" adopt size(K key) Method get collection list The length of is :" + listLength);
14、leftPop(K key)
Remove the first element on the left in the collection .
Object popValue = redisTemplate.opsForList().leftPop("list");
System.out.print(" adopt leftPop(K key) The element removed by the method is :" + popValue);
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(", The remaining elements are :" + list);
15、leftPop(K key, long timeout, TimeUnit unit)
Remove the left element of the collection in the waiting time , If there is no element after waiting time, exit .
popValue = redisTemplate.opsForList().leftPop("presentList",1, TimeUnit.SECONDS);
System.out.print(" adopt leftPop(K key, long timeout, TimeUnit unit) The element removed by the method is :" + popValue);
list = redisTemplate.opsForList().range("presentList",0,-1);
System.out.println(", The remaining elements are :" + list);
16、rightPop(K key)
Remove the element on the right side of the collection .
popValue = redisTemplate.opsForList().rightPop("list");
System.out.print(" adopt rightPop(K key) The element removed by the method is :" + popValue);
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(", The remaining elements are :" + list);
17、rightPop(K key, long timeout, TimeUnit unit)
Remove the elements on the right side of the collection in the waiting time , If there is no element after waiting time, exit .
popValue = redisTemplate.opsForList().rightPop("presentList",1, TimeUnit.SECONDS);
System.out.print(" adopt rightPop(K key, long timeout, TimeUnit unit) The element removed by the method is :" + popValue);
list = redisTemplate.opsForList().range("presentList",0,-1);
System.out.println(", The remaining elements are :" + list);
18、rightPopAndLeftPush(K sourceKey, K destinationKey)
Remove the element on the right side of the collection , At the same time, add an element on the left .
popValue = redisTemplate.opsForList().rightPopAndLeftPush("list","12");
System.out.print(" adopt rightPopAndLeftPush(K sourceKey, K destinationKey) The element removed by the method is :" + popValue);
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(", The remaining elements are :" + list);
19、rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit)
Remove the elements on the right side of the collection in the waiting time , At the same time, add elements on the left , If there is no element after waiting time, exit .
popValue = redisTemplate.opsForList().rightPopAndLeftPush("presentList","13",1,TimeUnit.SECONDS);
System.out.println(" adopt rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit) The element removed by the method is :" + popValue);
list = redisTemplate.opsForList().range("presentList",0,-1);
System.out.print(", The remaining elements are :" + list);
20、set(K key, long index, V value)
* Inserts an element at the specified location in the collection *, If an element already exists at the specified location , Coverage , If not, add , Exceeds the subscript set *+n* May be an error .
redisTemplate.opsForList().set("presentList",3,"15");
list = redisTemplate.opsForList().range("presentList",0,-1);
System.out.print(" adopt set(K key, long index, V value) Method after adding an element at the specified position :" + list);
21*、remove(K key, long count, Object value)
The first count event to remove an element equal to the value from the list stored in the key .count> 0: Delete the first element equal to the value moved from left to right ;count< 0: The value of the first element moved from left to right is equal to that of the first element deleted ;count = 0: Delete equals value All elements of .
long removeCount = redisTemplate.opsForList().remove("list",0,"w");
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt remove(K key, long count, Object value) Method to remove the number of elements :" + removeCount);
System.out.println(", The remaining elements :" + list);
22、trim(K key, long start, long end)
Intercept the length of set elements , Data within retention length .
redisTemplate.opsForList().trim("list",0,5);
list = redisTemplate.opsForList().range("list",0,-1);
System.out.println(" adopt trim(K key, long start, long end) Method to intercept the remaining elements :" + list);
边栏推荐
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
- Acdreamoj1110 (multiple backpacks)
- for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
- El table table - sortable sorting & disordered sorting when decimal and% appear
- [in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
- 跨分片方案 总结
- js中,字符串和数组互转(二)——数组转为字符串的方法
- 038. (2.7) less anxiety
- 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
- WEB功能测试说明
猜你喜欢

KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐

基于深度学习的参考帧生成

None of the strongest kings in the monitoring industry!

After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers

快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”

3D face reconstruction: from basic knowledge to recognition / reconstruction methods!

监控界的最强王者,没有之一!

Opencv learning example code 3.2.3 image binarization
![[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)](/img/1c/973f824f061d470a4079487d75f0d0.png)
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)

爱可可AI前沿推介(7.6)
随机推荐
SDL2来源分析7:演出(SDL_RenderPresent())
首批入选!腾讯安全天御风控获信通院业务安全能力认证
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
Notes - detailed steps of training, testing and verification of yolo-v4-tiny source code
Opencv learning example code 3.2.3 image binarization
js中,字符串和数组互转(一)——字符串转为数组的方法
string的底层实现
Pat 1078 hashing (25 points) ⼆ times ⽅ exploration method
Data Lake (VIII): Iceberg data storage format
启动嵌入式间:资源有限的系统启动
ROS error: could not find a package configuration file provided by "move_base“
Aike AI frontier promotion (7.6)
El table table - sortable sorting & disordered sorting when decimal and% appear
[MySQL] trigger
Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]
R3live notes: image processing section
It's almost the new year, and my heart is lazy
Technology sharing | packet capturing analysis TCP protocol
Nodejs教程之Expressjs一篇文章快速入门
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics