当前位置:网站首页>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);
边栏推荐
- 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
- 缓存更新策略概览(Caching Strategies Overview)
- 面试官:Redis中有序集合的内部实现方式是什么?
- 【mysql】游标的基本使用
- 039. (2.8) thoughts in the ward
- Manifest of SAP ui5 framework json
- OAI 5g nr+usrp b210 installation and construction
- MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
- 愛可可AI前沿推介(7.6)
- 对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
猜你喜欢
Common English vocabulary that every programmer must master (recommended Collection)
Opencv learning example code 3.2.3 image binarization
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
[interpretation of the paper] machine learning technology for Cataract Classification / classification
Data Lake (VIII): Iceberg data storage format
2022 fields Award Announced! The first Korean Xu Long'er was on the list, and four post-80s women won the prize. Ukrainian female mathematicians became the only two women to win the prize in history
Why does MySQL index fail? When do I use indexes?
防火墙基础之外网服务器区部署和双机热备
Reference frame generation based on deep learning
Aike AI frontier promotion (7.6)
随机推荐
Web开发小妙招:巧用ThreadLocal规避层层传值
Notes - detailed steps of training, testing and verification of yolo-v4-tiny source code
The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
Why does MySQL index fail? When do I use indexes?
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
在最长的距离二叉树结点
js中,字符串和数组互转(二)——数组转为字符串的方法
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
技术分享 | 抓包分析 TCP 协议
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
Description of web function test
@Detailed differences among getmapping, @postmapping and @requestmapping, with actual combat code (all)
How to implement common frameworks
JS get array subscript through array content
js通过数组内容来获取数组下标
js中,字符串和数组互转(一)——字符串转为数组的方法
OAI 5g nr+usrp b210 installation and construction
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)
SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍