redis cluster 模式如何批量删除指定前缀的key
2017-08-16 10:19
696 查看
public static void delKeys(HostAndPort hostAndPort, String keysPattern) { Map<String, JedisPool> clusterNodes = getJedisCluster(hostAndPort).getClusterNodes(); for (Map.Entry<String, JedisPool> entry : clusterNodes.entrySet()) { Jedis jedis = entry.getValue().getResource(); if (!jedis.info("replication").contains("role:slave")) { Set<String> keys = jedis.keys(keysPattern); if (keys.size() > 0) { Map<Integer, List<String>> map = new HashMap<>(6600); for (String key : keys) { int slot = JedisClusterCRC16.getSlot(key);//cluster模式执行多key操作的时候,这些key必须在同一个slot上,不然会报:JedisDataException: CROSSSLOT Keys in request don't hash to the same slot //按slot将key分组,相同slot的key一起提交 if (map.containsKey(slot)) { map.get(slot).add(key); } else { map.put(slot, Lists.newArrayList(key)); } } for (Map.Entry<Integer, List<String>> integerListEntry : map.entrySet()) { jedis.del(integerListEntry.getValue().toArray(new String[integerListEntry.getValue().size()])); } } } } }
相关文章推荐
- 使用CMD模式批量删除指定目录(支持目录中多层文件夹嵌套)下指定格式文件
- MySQL中批量删除指定前缀表的sql语句
- php批量删除数据库下指定前缀的表以prefix_为例
- win7 如何批量删除指定日期以前的文件
- Mysql如何批量删除具有相同表前缀的数据表(纯SQL语句)
- redis cluster模式key的模糊删除-java操作
- 获取Redis所有Key / 删除指定前缀的Key
- mysql批量删除指定前缀的表,批量修改表名的SQL语句
- 如何批量删除指定文件或以什么结尾的文件
- Mysql如何批量删除相同前缀的数据表
- 今天遇到了批量删除 redis 某个前缀的所有 key,发现只能是这么解决。
- bat如何批量删除指定部分文件夹名的文件夹
- 如何批量删除redis中的key
- redis集群批量删除指定的key
- 如何批量删除指定路径中的所有内容为空的文件夹
- MySQL中批量删除指定前缀表的sql语句
- java redis 删除指定前缀的key
- php批量删除数据库下指定前缀的表以prefix_为例
- Redis【知识点】批量删除指定Key
- php怎么批量删除数据库下指定前缀的表?