- import redis.clients.jedis.Jedis;
- import redis.clients.jedis.params.ScanParams;
- import redis.clients.jedis.resps.ScanResult;
-
- import java.util.List;
-
-
- public class test01 {
-
- public static void main(String[] args) {
- System.out.println("开始啦啦啦");
-
- Jedis jedis = new Jedis("127.0.0.1", 6379); //链接redis
-
- jedis.auth("password"); //密码
- jedis.select(1);
- // Long a = jedis.dbSize();
- ScanParams scanParams = new ScanParams();
- //模糊匹配的redis的键
- scanParams.match("*");
- //每次查询的条数
-
- scanParams.count(100);
- String scanStart = "0";
- // ScanResult
scan1 = jedis.scan(scanStart, scanParams); - while (true) {
- ScanResult
scan = jedis.scan(scanStart, scanParams); - scanStart = scan.getCursor();
- List
resultList = scan.getResult(); -
- //System.out.println("resultList:"+resultList);
- for (int i = 0; i < resultList.size(); i++) {
- // System.out.println("w娃哈哈2::" + resultList.get(i));
-
- jedis.del(resultList.get(i));
- }
- if (resultList == null || resultList.size() == 0) {
- System.out.println("删除完毕" );
- break;
- }
- if ("0".equals(scanStart)) {
- System.out.println("删除完毕" );
- break;
- }
-
- }
-
-
- }
- }