如何使用 Lettuce 和 Redis 异步调用 Geo 命令

How to invoke Geo commands with Lettuce's and Redis asynchronously

我正在尝试使用生菜来向 Redis 添加地理位置。 我设法使用同步方法做到了。

是否可以使用异步 api 来转换此逻辑?

同步代码:

StatefulRedisConnection<String, String> connection= client.connect();
RedisCommands syncCommands=syncCommands = connection.sync()
long result = syncCommands.geoadd(key, longitude, latitude, userId);

如何将其转换为异步调用?

谢谢, 雷.

尝试:

StatefulRedisConnection<String, String> connection= client.connect();
RedisAsyncCommands<String, String> asyncCommands = connection.async()
RedisFuture<Long> result = asyncCommands.geoadd(key, longitude, latitude, userId);

lettuce 4.0 允许在一个连接(同步、异步和反应式)上使用不同的 APIs。这与生菜 3.x 不同,其中 API 样式与连接相结合。

只需调用连接对象的async()方法即可获得异步API。您可以找到有关异步 API in the Wiki.

的更多信息