Java redis获取所有key

  • 方法一:
public List getAllKeys() {
            return redisClient.Key().keys("*");
}
  • 方法二:
public List getAllKeys() {
        List list = new ArrayList<>();
        boolean isFinished = false;
        KeyScanCursor rst = null;
        while (!isFinished) {
            rst = redisClient.Key().scan("mock*", rst);
            isFinished = rst.isFinished();
            if(rst.getKeys() != null && rst.getKeys().size()!=0){
                list.addAll(rst.getKeys());
            }
        }
        return list;
}

你可能感兴趣的:(Java redis获取所有key)