Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Jedis and Lettuce async abilities

$
0
0

I am using redis with Akka so I need no blocking calls. Lettuce has async-future call built into it. But Jedis is the recommended client by Redis. Can someone tell me if I am using both of them the right way. If so which one is better.

JEDISI am using a static Jedis connection pool to get con and using Akka future callback to process the result. My concern here is when I use another thread (callable) to get the result that thread is eventually going to block for the result. While Lettuce might have some more efficient way of doing this.

 private final class OnSuccessExtension extends OnSuccess<String> {            private final ActorRef senderActorRef;            private final Object message;            @Override            public void onSuccess(String valueRedis) throws Throwable {                log.info(getContext().dispatcher().toString());                senderActorRef.tell((String) message, ActorRef.noSender());            }             public OnSuccessExtension(ActorRef senderActorRef,Object message) {                    this.senderActorRef = senderActorRef;                    this.message=message;                }        }        ActorRef senderActorRef = getSender(); //never close over a future            if (message instanceof String) {        Future<String> f =akka.dispatch.Futures.future(new Callable<String>() {                    public String call() {                        String result;                        try(Jedis jedis=JedisWrapper.redisPool.getResource()) {                            result = jedis.get("name");                        }                        return result;                    }                }, ex);                f.onSuccess(new OnSuccessExtension(senderActorRef,message), ex);    }

LETTUCE

ExecutorService executorService = Executors.newFixedThreadPool(10);public void onReceive(Object message) throws Exception {        ActorRef senderActorRef = getSender(); //never close over a future        if (message instanceof String) {            final RedisFuture<String> future = lettuce.connection.get("name");            future.addListener(new Runnable() {                final ActorRef sender = senderActorRef;                final String msg =(String) message;                @Override                public void run() {                    try {                        String value = future.get();                        log.info(value);                        sender.tell(message, ActorRef.noSender());                    } catch (Exception e) {                    }                }            }, executorService);

If lettuce is a better option for Async calls. Then what type of executor should I go with in production environment. If possible can I use a Akka dispatcher as an execution context for Letture future call.


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>