您的位置:宽带测速网 > 网络知识 > redis如何循环遍历key

redis如何循环遍历key

2025-06-17 10:10来源:互联网 [ ]

redis循环遍历key的示例:

@Test

public void test12(){

Jedis jedis = new Jedis("x.x.x.x", 6379);

jedis.auth("xxx");

long start = System.currentTimeMillis();

String cursor = "0";

do {

ScanParams scanParams = new ScanParams();

scanParams.match("hello*");

ScanResult scan = jedis.scan(cursor, scanParams);

List result = scan.getResult();

result.forEach(x->{

System.out.println(x);

});

cursor = scan.getStringCursor();

}while (!StringUtils.equals("0",cursor));

long end = System.currentTimeMillis();

System.out.println(new Double(end-start)/1000d);

}