简体   繁体   中英

Does Jedis support async operations

I am using Jedis (java client) to commmunicate with Redis server. I have 3 Redis instances running on three different nodes. I want to "get" (read) some records from 3 Redis instances. I want to issue these "gets" (reads) in parallel, and then do some processing on the received data and form a final output.

What is the best way to do this in java?

One of the way is to create 3 threads and isssue "get" (read) in each of them (synchronously). Wait for all 3 commands to complete and then combine the result.

Does Jedis have a mechanism for issuing 3 "gets" (any command for that matter) asynchronously, with a callback feature?


I have 3 different Redis instances. So do you suggest to use "ShardedJedisPipeline" (jedis/tests/ShardedJedisPipelineTest.java) for interacting with these Redis instances in parallel?

Normal Jedis Pipeline (jedis/tests/PipeliningTest.java), just sends multiple commands to single Redis instance so they are executed one after other on Redis server (and all responses available at the end).

So I assume I have to use "ShardedJedisPipeline". But there are two limitations to this: 1. I want to execute Lua script ie "eval" on 3 Redis instances in parallel. 2. I dont want sharding (some hash algorithm used by Jedis) to distribute data or on its own (using its algorithm) read data from instances. We have a different strategy for distributing data. So I want to be able to specify, a record should be stored in which redis instance and accordingly from where it should be read. keyTags seems to provide this mechanism but not sure how to use this with "eval".

You can use pipeline as mentioned. AsyncJedis is a work is progress and will be released with the next version of Jedis. It will be based on netty and will be compatible with vert.x

在此之前,您可以使用带有三个Jedis实例的ExecutorService自行滚动它,然后等待返回的期货。

As far as Feb 2015, Jedis apparently does not support Async operation over a single redis instance as you need: https://github.com/xetorthio/jedis/issues/241

What I would do in your case is go ahead with 3 threads and proceed with Futures and Executor Service as @Xorlev suggested above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM