redis中使用scan正則表達式檢索所有key


  /**
   * 使用scan正則表達式檢索
   *
   * @param regex 正則表達式
   * @param count 增量迭代
   */
  public Set<String> scan(String regex, long count) {
    ScanOptions options = ScanOptions.scanOptions()
        .match(regex)
        .count(count)
        .build();
    return redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
      Set<String> keys = new HashSet<>();
      Cursor<byte[]> cursor = connection.scan(options);
      while (cursor.hasNext()) {
        keys.add(new String(cursor.next()));
      }
      return keys;
    });
  }

參考
https://www.jianshu.com/p/4c842c41ba41


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM