Reputation: 435
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
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