redis如何循环遍历key

1184
2021/1/14 9:14:33
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

redis如何循环遍历key

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);

}

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: 编译安装redis配置文件在哪里