如何在Lettuce中使用RedisAsyncCommands时同时从RedisFuture获取键和值

时间:2019-10-03 07:58:22

标签: java redis lettuce

如何在Lettuce中使用RedisAsyncCommands时同时从RedisFuture获取键和值。

RedisClient redisClient = RedisClient .create("redis://localhost:6379/");
StatefulRedisConnection<String, String> connection = redisClient.connect();
RedisAsyncCommands<String, String> commands = connection.async();

// disable auto-flushing
commands.setAutoFlushCommands(false);

List<RedisFuture<?>> futures = new ArrayList<>();
for (int i = 0; i < 10; i++) {
    futures.add(commands.get("key-" + i));
}

commands.flushCommands();

for(RedisFuture future : futures) {
    System.out.println(future.get()); //Giving only values.
}
connection.close();

所以我的期望是我也需要键对象以及RedisFuture对象的值。 这是因为在我的真实示例中,可能存在特定键没有值的可能性,因此我需要掌握以下信息:我从高速缓存中获取了哪些键的数据,因此可以从中创建映射。

请忽略我的错别字和语法错误。

0 个答案:

没有答案