redis 使用Jedis 控制操作
2. 使用keys进行模糊查询
public static Set<String> redisKeys(String pattern) {
Set<String> keys = new HashSet<>();
//获取所有连接池节点
Map<String, JedisPool> nodes = jedis.getClusterNodes();
//遍历所有连接池,逐个进行模糊查询
for (String k : nodes.keySet()) {
JedisPool pool = nodes.get(k);
//获取Jedis对象,Jedis对象支持keys模糊查询
Jedis connection = pool.getResource();
try {
keys.addAll(connection.keys(pattern));
} catch (Exception e) {
System.out.println("获取key异常" + e);
} finally {
//一定要关闭连接!
connection.close();
}
}
return keys;
}
数量过大的时候使用keys 会发生redis 卡顿情况,
所有我们使scan方式进行每次匹配1000条
3.代码:`
// 使用scan方式进行查询
// 类似mysql中 limit进行分页查询
public static S