Search code examples
javaredislettuce

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


I am trying to use lettuce in order to add geolocations to Redis. I managed to do it using the sync methods.

Is it possible to convert this logic using the async api for lettue?

sync code:

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

How do you convert this into an async invocation?

Thanks, ray.


Solution

  • try:

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

    lettuce 4.0 allows to use different APIs with on one connection (synchronous, asynchronous and reactive). That's different to lettuce 3.x where the API style was coupled with the connection.

    Just call the async() method on the connection object to obtain the asynchronous API. You can find more about the asynchronous API in the Wiki.