当前位置:网站首页>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);
边栏推荐
- None of the strongest kings in the monitoring industry!
- 14年本科毕业,转行软件测试,薪资13.5K
- Proxy and reverse proxy
- OSPF multi zone configuration
- 互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地
- 3D人脸重建:从基础知识到识别/重建方法!
- 【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
- 2017 8th Blue Bridge Cup group a provincial tournament
- el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
- 对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
猜你喜欢
ICML 2022 | flowformer: task generic linear complexity transformer
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
【力扣刷题】32. 最长有效括号
Fastjson parses JSON strings (deserialized to list, map)
嵌入式开发的7大原罪
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
Swagger UI教程 API 文档神器
每个程序员必须掌握的常用英语词汇(建议收藏)
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
随机推荐
document.write()的用法-写入文本——修改样式、位置控制
Binary tree node at the longest distance
This year, Jianzhi Tencent
Math symbols in lists
Interviewer: what is the internal implementation of ordered collection in redis?
字符串的使用方法之startwith()-以XX开头、endsWith()-以XX结尾、trim()-删除两端空格
PG basics -- Logical Structure Management (transaction)
JS操作dom元素(一)——获取DOM节点的六种方式
Seven original sins of embedded development
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)
Mtcnn face detection
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
启动嵌入式间:资源有限的系统启动
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
What's the best way to get TFS to output each project to its own directory?
js之遍历数组、字符串
Deployment of external server area and dual machine hot standby of firewall Foundation
@PathVariable
038. (2.7) less anxiety
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools