当前位置:网站首页>Redistemplate common collection instructions opsforhash (IV)
Redistemplate common collection instructions opsforhash (IV)
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 opsForHash() Use of methods :
1、put(H key, HK hashKey, HV value)
newly added hashMap value .
redisTemplate.opsForHash().put("hashValue","map1","map1-1");
redisTemplate.opsForHash().put("hashValue","map2","map2-2");
2、values(H key)
Gets the value in the specified variable hashMap value .
List<Object> hashList = redisTemplate.opsForHash().values("hashValue");
System.out.println(" adopt values(H key) Method to get the in the variable hashMap value :" + hashList);
3、entries(H key)
Get the key value pair in the variable .
Map<Object,Object> map = redisTemplate.opsForHash().entries("hashValue");
System.out.println(" adopt entries(H key) Method to get the key value pair in the variable :" + map);
4、get(H key, Object hashKey)
Gets the specified value in the variable map Does the key have a value , If the map Key to get the value , No return null.
Object mapValue = redisTemplate.opsForHash().get("hashValue","map1");
System.out.println(" adopt get(H key, Object hashKey) Method to get map Value of key :" + mapValue);
5、hasKey(H key, Object hashKey)
Determine whether there is a specified... In the variable map key .
boolean hashKeyBoolean = redisTemplate.opsForHash().hasKey("hashValue","map3");
System.out.println(" adopt hasKey(H key, Object hashKey) Method to determine whether there is map key :" + hashKeyBoolean);
6、keys(H key)
Get the key in the variable .
Set<Object> keySet = redisTemplate.opsForHash().keys("hashValue");
System.out.println(" adopt keys(H key) Method to get the key in the variable :" + keySet);
7、size(H key)
Get the length of the variable .
long hashLength = redisTemplate.opsForHash().size("hashValue");
System.out.println(" adopt size(H key) Method to get the length of the variable :" + hashLength);
8、increment(H key, HK hashKey, double delta)
Make the key in the variable with double The size of the value increases by itself .
double hashIncDouble = redisTemplate.opsForHash().increment("hashInc","map1",3);
System.out.println(" adopt increment(H key, HK hashKey, double delta) Method to make the key in the variable self grow with the size of the value :" + hashIncDouble);
9、increment(H key, HK hashKey, long delta)
Make the key in the variable with long The size of the value increases by itself .
long hashIncLong = redisTemplate.opsForHash().increment("hashInc","map2",6);
System.out.println(" adopt increment(H key, HK hashKey, long delta) Method to make the key in the variable self grow with the size of the value :" + hashIncLong);
10、multiGet(H key, Collection hashKeys)
Get the value in the variable as a collection .
List<Object> list = new ArrayList<Object>();
list.add("map1");
list.add("map2");
List mapValueList = redisTemplate.opsForHash().multiGet("hashValue",list);
System.out.println(" adopt multiGet(H key, Collection<HK> hashKeys) Method to get the value in the variable in the form of a collection :"+mapValueList);
11、putAll(H key, Map<? extends HK,? extends HV> m)
With map Add key value pairs in the form of sets .
Map newMap = new HashMap();
newMap.put("map3","map3-3");
newMap.put("map5","map5-5");
redisTemplate.opsForHash().putAll("hashValue",newMap);
map = redisTemplate.opsForHash().entries("hashValue");
System.out.println(" adopt putAll(H key, Map<? extends HK,? extends HV> m) Methods to map Add key value pairs in the form of sets :" + map);
12、putIfAbsent(H key, HK hashKey, HV value)
If the variable value exists , You can add non-existent key value pairs to variables , If the variable does not exist , Then add a new variable , At the same time, add the key value pair to the variable .
redisTemplate.opsForHash().putIfAbsent("hashValue","map6","map6-6");
map = redisTemplate.opsForHash().entries("hashValue");
System.out.println(" adopt putIfAbsent(H key, HK hashKey, HV value) Method to add a key value pair that does not exist in the variable :" + map);
13、scan(H key, ScanOptions options)
Match to get key value pairs ,ScanOptions.NONE To get all key pairs ,ScanOptions.scanOptions().match(“map1”).build() Match to get the key map1 The key/value pair *,* No fuzzy matching .
Cursor<Map.Entry<Object,Object>> cursor = redisTemplate.opsForHash().scan("hashValue",ScanOptions.scanOptions().match("map1").build());
//Cursor<Map.Entry<Object,Object>> cursor = redisTemplate.opsForHash().scan("hashValue",ScanOptions.NONE);
while (cursor.hasNext()){
Map.Entry<Object,Object> entry = cursor.next();
System.out.println(" adopt scan(H key, ScanOptions options) Method to get a matching key value pair :" + entry.getKey() + "---->" + entry.getValue());
}
14、delete(H key, Object… hashKeys)
Delete key value pairs in variables , Multiple parameters can be passed in , Delete multiple key value pairs *.*
redisTemplate.opsForHash().delete("hashValue","map1","map2");
map = redisTemplate.opsForHash().entries("hashValue");
System.out.println(" adopt delete(H key, Object... hashKeys) Method deletes the remaining key value pairs in the variable :" + map);
边栏推荐
- Swagger UI tutorial API document artifact
- Forward maximum matching method
- Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
- 数据湖(八):Iceberg数据存储格式
- js中,字符串和数组互转(一)——字符串转为数组的方法
- The biggest pain point of traffic management - the resource utilization rate cannot go up
- How to implement common frameworks
- 爱可可AI前沿推介(7.6)
- MySQL - 事务(Transaction)详解
- Web开发小妙招:巧用ThreadLocal规避层层传值
猜你喜欢
面试官:Redis中有序集合的内部实现方式是什么?
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
监控界的最强王者,没有之一!
2017 8th Blue Bridge Cup group a provincial tournament
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
The biggest pain point of traffic management - the resource utilization rate cannot go up
Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
随机推荐
Reinforcement learning - learning notes 5 | alphago
R language visualizes the relationship between more than two classification (category) variables, uses mosaic function in VCD package to create mosaic plots, and visualizes the relationship between tw
el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
Swagger UI tutorial API document artifact
数据湖(八):Iceberg数据存储格式
Yyds dry inventory run kubeedge official example_ Counter demo counter
Regular expression collection
Vim 基本配置和经常使用的命令
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
分糖果
[go][转载]vscode配置完go跑个helloworld例子
Absolute primes (C language)
How do I remove duplicates from the list- How to remove duplicates from a list?
【力扣刷题】32. 最长有效括号
966 minimum path sum
js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
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
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
Web开发小妙招:巧用ThreadLocal规避层层传值
JS操作dom元素(一)——获取DOM节点的六种方式