【问题标题】:How to invoke Geo commands with Lettuce's and Redis asynchronously如何使用 Lettuce 和 Redis 异步调用 Geo 命令
【发布时间】:2015-09-09 09:59:26
【问题描述】:

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

是否可以使用 lettue 的 async api 转换此逻辑?

同步代码:

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

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

谢谢, 射线。

【问题讨论】:

    标签: java redis lettuce


    【解决方案1】:

    尝试:

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

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

    只需在连接对象上调用async()方法即可获取异步API。您可以找到有关异步 API in the Wiki 的更多信息。

    【讨论】:

    • 什么时候可以稳定发布 lettuce 4?:)
    • 九月底/十月初
    猜你喜欢
    • 2019-01-22
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 2014-04-29
    • 2013-02-15
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    相关资源
    最近更新 更多