当前位置:网站首页>Redistemplate common collection instructions opsforvalue (II)
Redistemplate common collection instructions opsforvalue (II)
2022-07-06 05:45:00 【Python's path to immortality】
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 opsForValue() Use of methods :
1、set(K key, V value)
Add a value of string type ,key It's a key ,value Is the value .
redisTemplate.opsForValue().set("stringValue","bbb");
2、get(Object key)
obtain key The value of the key .
String stringValue = redisTemplate.opsForValue().get("stringValue")+"";
System.out.println(" adopt get(Object key) Method to get set(K key, V value) Method to add a new string value :" + stringValue);
3、append(K key, String value)
Add a new string to the end based on the original value .
redisTemplate.opsForValue().append("stringValue","aaa");
String stringValueAppend = redisTemplate.opsForValue().get("stringValue")+"";
System.out.println(" adopt append(K key, String value) Method to modify the string :"+stringValueAppend);
4、get(K key, long start, long end)
Intercept key The key corresponds to the value string , From the start subscript position to the end subscript position ( Include end subscript ) String .
String cutString = redisTemplate.opsForValue().get("stringValue",0,3);
System.out.println(" adopt get(K key, long start, long end) Method to get the intercepted string :"+cutString);
5、getAndSet(K key, V value)
Get the original key Key and assign a new value .
String oldAndNewStringValue = redisTemplate.opsForValue().getAndSet("stringValue","ccc")+"";
System.out.print(" adopt getAndSet(K key, V value) Method to get the original " + oldAndNewStringValue + ",");
String newStringValue = redisTemplate.opsForValue().get("stringValue")+"";
System.out.println(" Modified value :"+newStringValue);
6、setBit(K key, long offset, boolean value)
key The value of the key value Corresponding ascii code , stay offset The location of ( Count from left to right ) Turn into value.
redisTemplate.opsForValue().setBit("stringValue",1,false);
newStringValue = redisTemplate.opsForValue().get("stringValue")+"";
System.out.println(" adopt setBit(K key,long offset,boolean value) Method modified value :"+newStringValue);
7、getBit(K key, long offset)
Determine the specified location ASCII The code bit Whether a is 1.
boolean bitBoolean = redisTemplate.opsForValue().getBit("stringValue",1);
System.out.println(" adopt getBit(K key,long offset) Method judgment assignment bit The value of bits is :" + bitBoolean);
8、size(K key)
Gets the length of the specified string .
Long stringValueLength = redisTemplate.opsForValue().size("stringValue");
System.out.println(" adopt size(K key) Method to get the length of the string :"+stringValueLength);
9、increment(K key, double delta)
Incrementally move double Values are stored in variables .
double stringValueDouble = redisTemplate.opsForValue().increment("doubleValue",5);
System.out.println(" adopt increment(K key, double delta) Method to store... Incrementally double value :" + stringValueDouble);
10、increment(K key, long delta)
Incrementally move long Values are stored in variables .
double stringValueLong = redisTemplate.opsForValue().increment("longValue",6);
System.out.println(" adopt increment(K key, long delta) Method to store... Incrementally long value :" + stringValueLong);
11、setIfAbsent(K key, V value)
If the key does not exist, add it , Being does not change the value that is already there .
boolean absentBoolean = redisTemplate.opsForValue().setIfAbsent("absentValue","fff");
System.out.println(" adopt setIfAbsent(K key, V value) Method to determine the value of the variable absentValue Whether there is :" + absentBoolean);
if(absentBoolean){
String absentValue = redisTemplate.opsForValue().get("absentValue")+"";
System.out.print(", non-existent , Then the new value is :"+absentValue);
boolean existBoolean = redisTemplate.opsForValue().setIfAbsent("absentValue","eee");
System.out.print(", Call again setIfAbsent(K key, V value) Judge absentValue Whether it exists and reassigns :" + existBoolean);
if(!existBoolean){
absentValue = redisTemplate.opsForValue().get("absentValue")+"";
System.out.print(" If there is , After re assignment absentValue The value of the variable is :" + absentValue);
}
}
12、set(K key, V value, long timeout, TimeUnit unit)
Set the expiration time of the variable value .
redisTemplate.opsForValue().set("timeOutValue","timeOut",5,TimeUnit.SECONDS);
String timeOutValue = redisTemplate.opsForValue().get("timeOutValue")+"";
System.out.println(" adopt set(K key, V value, long timeout, TimeUnit unit) Method to set the expiration time , Data obtained before expiration :"+timeOutValue);
Thread.sleep(5*1000);
timeOutValue = redisTemplate.opsForValue().get("timeOutValue")+"";
System.out.print(", wait for 10s later , Get the value of :"+timeOutValue);
13、set(K key, V value, long offset)
Overwrite the value starting from the specified position .
redisTemplate.opsForValue().set("absentValue","dd",1);
String overrideString = redisTemplate.opsForValue().get("absentValue")+"";
System.out.println(" adopt set(K key, V value, long offset) Method covers the value of the part :"+overrideString);
14、multiSet(Map<? extends K,? extends V> map)
Set up map Assemble to redis.
Map valueMap = new HashMap();
valueMap.put("valueMap1","map1");
valueMap.put("valueMap2","map2");
valueMap.put("valueMap3","map3");
redisTemplate.opsForValue().multiSet(valueMap);
15、multiGet(Collection keys)
Take out the corresponding... According to the set value value .
// according to List Set to get the corresponding value value
List paraList = new ArrayList();
paraList.add("valueMap1");
paraList.add("valueMap2");
paraList.add("valueMap3");
List<String> valueList = redisTemplate.opsForValue().multiGet(paraList);
for (String value : valueList){
System.out.println(" adopt multiGet(Collection<K> keys) Method to get map value :" + value);
}
16、multiSetIfAbsent(Map<? extends K,? extends V> map)
If the corresponding map Collection name does not exist , Then add , If it exists, it will not be modified .
Map valueMap = new HashMap();
valueMap.put("valueMap1","map1");
valueMap.put("valueMap2","map2");
valueMap.put("valueMap3","map3");
redisTemplate.opsForValue().multiSetIfAbsent(valueMap);
This is the end of the introduction opsForValue() Use of methods , The specific code will be given in the last article .
边栏推荐
- [detailed explanation of Huawei machine test] statistics of shooting competition results
- 入侵检测领域数据集总结
- 01. 开发博客项目之项目介绍
- Selective parameters in MATLAB functions
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- LeetCode_字符串反转_简单_557. 反转字符串中的单词 III
- Embedded interview questions (IV. common algorithms)
- B站刘二大人-数据集及数据加载 Lecture 8
- 查询生产订单中某个(些)工作中心对应的标准文本码
- 29io stream, byte output stream continue write line feed
猜你喜欢

SequoiaDB湖仓一体分布式数据库2022.6月刊

ArcGIS application foundation 4 thematic map making
![[JVM] [Chapter 17] [garbage collector]](/img/f4/e6ff0e3edccf23399ec12b7913749a.jpg)
[JVM] [Chapter 17] [garbage collector]
[SQL Server fast track] - authentication and establishment and management of user accounts

Game push image / table /cv/nlp, multi-threaded start

Migrate Infones to stm32

Garbage collector with serial, throughput priority and response time priority

Deep learning -yolov5 introduction to actual combat click data set training

Redis message queue

【经验】win11上安装visio
随机推荐
【云原生】3.1 Kubernetes平台安装KubeSpher
Vulhub vulnerability recurrence 69_ Tiki Wiki
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
H3C防火墙RBM+VRRP 组网配置
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
05. 博客项目之安全
【华为机试真题详解】统计射击比赛成绩
03. Login of development blog project
Processes and threads
Yygh-11-timing statistics
[force buckle]43 String multiplication
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
通讯录管理系统链表实现
[experience] install Visio on win11
B站刘二大人-反向传播
授予渔,从0开始搭建一个自己想要的网页
Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028
First knowledge database
网络协议模型
PDK process library installation -csmc