Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 i.e. "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".

like image 257
sunillp Avatar asked Nov 03 '22 20:11

sunillp


1 Answers

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

like image 65
xetorthio Avatar answered Nov 12 '22 11:11

xetorthio