Authored by qinchao

redis 删除

... ... @@ -335,25 +335,33 @@ public class RedisCommonUtil {
try {
client=new Jedis(host, port);
ScanParams scanParams = new ScanParams();
scanParams.count(1000);//每次扫描多少条记录,值越大消耗的时间越短,但会影响redis性能。建议设为一千到一万
scanParams.match(prefix+"*");
List<String> list;
List<String> listAllKey=new ArrayList<>();
ScanResult<String> sr;
String nextCursor="0";
String nextCursor = ScanParams.SCAN_POINTER_START;
do {
sr = client.scan(nextCursor,scanParams);
nextCursor=new String(sr.getCursorAsBytes(),"UTF-8");
if(sr!=null){
list = sr.getResult();
List<String> list = sr.getResult();
if(list!=null&&list.size()>0){
total = total+(list.size());
String[] arr = list.toArray(new String[list.size()]);
client.del(arr);
listAllKey.addAll(list);
}
}
nextCursor=new String(sr.getCursorAsBytes(),"UTF-8");
}while (!nextCursor.equals("0"));
//删除
logger.info("removeRedisKeyByPrefix {} ",listAllKey);
total = 0L+ listAllKey.size();
if(total>0){
String[] arr = listAllKey.toArray(new String[listAllKey.size()]);
client.del(arr);
}
}catch (Exception e){
logger.error(e.toString());
}finally {
... ...