titan
titan

Reputation: 435

Is there a redis library which handles the pipelining automatically?

I am looking at the possibility of triggering the redis command from the client as a normal api and the library can pipeline the commands into it and possibly reply asynchronously back. Any library for the Java would be highly appreciated.

Any pointers to opensource work on the same lines would also be of the great help.

Upvotes: 4

Views: 3000

Answers (2)

Nikita Koksharov
Nikita Koksharov

Reputation: 10803

Redisson provides asynchronous pipeline in more convenient way. Here is code example:

RBatch batch = redisson.createBatch();
RFuture<String> mapFuture = batch.getMap("test").putAsync("2", "5");
RFuture<Long> longFuture = batch.getAtomicLongAsync("counter").incrementAndGetAsync();

List<?> res = batch.execute();
// or 
RFuture<List<?>> asyncRes = batch.executeAsync();

Asynchronous methods returns RFuture object which implements both CompletionStage and Future interfaces.

Further, you can get result

mapFuture.get() result or asyncRes.get()[0]

Binding listeners:

future.whenComplete((res, exception) -> {

  // handle both result and exception

});

// or

future.thenAccept(res -> {

  // handle result

}).exceptionally(exception -> {

  // handle exception

});

Upvotes: 2

mp911de
mp911de

Reputation: 18137

Both popular Java Redis clients, Jedis and lettuce provide async/pipelining. See here for an example. You get a Future after issuing commands so you can sync on your own or work with future callbacks.

Upvotes: 2

Related Questions