```private static void deleteAllKeys() {JedisCluster jedisCluster = new JedisCluster(new HostAndPort(127.0.0.1, 6379));try {// 获取集群中所有的节点CollectionJedisPool jedisPools = jedisCluster.get...
```
private static void deleteAllKeys() {
JedisCluster jedisCluster = new JedisCluster(new HostAndPort("127.0.0.1", 6379));
try {
// 获取集群中所有的节点
Collection<JedisPool> jedisPools = jedisCluster.getClusterNodes().values();
boolean isSuccess = false;
// 遍历所有的节点,获取每个节点上对应数据匹配的结果,并删除
for (JedisPool pool : jedisPools) {
Jedis jedis = null;
try {
jedis = pool.getResource();
Set<String> keys = jedis.keys("*");
Iterator<String> it = keys.iterator();
while (it.hasNext()) {
String key = it.next();
jedis.del(key);
}
pool.returnResource(jedis);
isSuccess = true;
} catch (JedisMovedDataException ignore) {
isSuccess = false;
pool.returnBrokenResource(jedis);
} catch (Exception e) {
pool.returnBrokenResource(jedis);
isSuccess = false;
System.out.println("Error message: " + e.getMessage());
}
}
if (isSuccess) {
System.out.println("Complete!");
} else {
System.out.println("Error!");
}
jedisCluster.close();
} catch (Exception e) {
try {
jedisCluster.close();
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
} }
```
沃梦达教程
本文标题为:redis集群删除所有数据
猜你喜欢
- Oracle 删除大量表记录操作分析总结 2023-07-23
- redis清除数据 2023-09-13
- 在阿里云CentOS 6.8上安装Redis 2023-09-12
- 搭建单机Redis缓存服务的实现 2023-07-13
- Mongodb启动报错完美解决方案:about to fork child process,waiting until server is ready for connections. 2023-07-16
- SQLSERVER调用C#的代码实现 2023-07-29
- 基于Python制作一个简单的文章搜索工具 2023-07-28
- Numpy中如何创建矩阵并等间隔抽取数据 2023-07-28
- SQL Server 2022 AlwaysOn新特性之包含可用性组详解 2023-07-29
- MySQL8.0.28安装教程详细图解(windows 64位) 2023-07-26