惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - Johnson_wang

对云服务器挂载cos桶 记录一次xxlJob升级版本导致的 xxl-job remoting error(Connection reset) 记一次NoClassDeffoundEror问题解决过程 nginx配置支持ws,并解决跨域 关于消费端接入dubbo,连接失败问题 RedisTemplate关于key出现前缀\xac\xed\x00\x05t\x00\x0f - Johnson_wang - 博客园 ES 单索引大表拆分 关于ES索引被聚合查询导致filedata堵塞 (pressure too high, (smooth) bulk request circuit break) 发送HTML格式邮件 elasticsearch报错FORBIDDEN/12/index read-only / allow delete spring Boot 相关问题以及修复(后续待补充) mybatis数据加解密处理方案 队列缓存区-db写入 synchronized的实现原理 Scheduler踩坑记录 关于HashMap的加载因子相关理解 Mybatis 分页插件PageHelper 遇坑 Linux 下 Mysql忘记密码重置 Eclipse MAT和jvisualvm分析内存溢出
关于RedisTemplate的map存储踩坑记录
Johnson_wang · 2020-07-29 · via 博客园 - Johnson_wang

现在需要在Redis中存储一个map,使用RedisTemplate 建立链接后,执行以下代码:

//cacheKey  缓存key
Map<String,String> map = new HashMap<String,String>();
map.put("a","1");
map.put("b","2");
map.put("c","3");
template.boundHashOps(cacheKey).putAll(map);

  发现Redis存储数据成功。

    现在想要修改map中的数据,当前需要批量修改 将 key = a/b 的数据value修改为3;

还是使用上面的逻辑,执行成功,数据变更。

现在想要把key=a的数据删除,写了如下代码:

Map<String,String> map = new HashMap<String,String>();
map.put("b","2");
map.put("c","3");
template.boundHashOps(cacheKey).putAll(map);

  发现Redis中当前cacheKey对应的数据还是3条记录,后面查看源码:

 public void putAll(K key, Map<? extends HK, ? extends HV> m) {
        if (!m.isEmpty()) {
            byte[] rawKey = this.rawKey(key);
            Map<byte[], byte[]> hashes = new LinkedHashMap(m.size());
            Iterator var5 = m.entrySet().iterator();

            while(var5.hasNext()) {
                Entry<? extends HK, ? extends HV> entry = (Entry)var5.next();
                hashes.put(this.rawHashKey(entry.getKey()), this.rawHashValue(entry.getValue()));
            }

            this.execute((connection) -> {
                connection.hMSet(rawKey, hashes);
                return null;
            }, true);
        }
    }

putAll方法只对传入的map对应key做了处理,并不是对整个缓存的key做覆盖,只能做追加和修改。

所以需要使用hdel删除对应key:

template.boundHashOps(cacheKey).delete(needRemoveKeys.toArray());