即使redis数据库中有成千上万的条目,此代码也仅返回100个结果:
RedisFuture<List<Object>> future = redis.dispatch(CommandType.SCAN, new ArrayOutput<String, String>(StringCodec.UTF8), new CommandArgs<String, String>(StringCodec.UTF8).add("aircraft"));
List<Object> result = Collections.emptyList();
try {
result = future.get();
} catch (InterruptedException | ExecutionException e) {
// TODO: Do something
}
if(result.size() > 1) {
@SuppressWarnings("unchecked")
List<List<String>> aircraft = (List<List<String>>) result.get(1);
Map<String, Aircraft> retval = aircraft.stream().collect(Collectors.toMap(it -> it.get(0), it -> {
try {
JsonNode positionJson = objectMapper.readTree(it.get(1)).get("coordinates");
return new Aircraft(positionJson.get(0).asDouble(), positionJson.get(1).asDouble());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}));
return retval;
} else {
return Collections.emptyMap();
}