sql >> Base de Datos >  >> NoSQL >> Redis

No se puede escanear usando la plantilla redis

Puede usar un RedisCallback en RedisOperations para hacerlo.

redisTemplate.execute(new RedisCallback<Iterable<byte[]>>() {

  @Override
  public Iterable<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {

    List<byte[]> binaryKeys = new ArrayList<byte[]>();

    Cursor<byte[]> cursor = connection.scan(ScanOptions.NONE);
    while (cursor.hasNext()) {
      binaryKeys.add(cursor.next());
    }

    try {
      cursor.close();
    } catch (IOException e) {
      // do something meaningful
    }

    return binaryKeys;
  }
});