简体   繁体   English

Jedis是否支持异步操作

[英]Does Jedis support async operations

I am using Jedis (java client) to commmunicate with Redis server. 我正在使用Jedis(java客户端)与Redis服务器进行通信。 I have 3 Redis instances running on three different nodes. 我在三个不同的节点上运行了3个Redis实例。 I want to "get" (read) some records from 3 Redis instances. 我想从3个Redis实例中“获取”(读取)一些记录。 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? 在java中执行此操作的最佳方法是什么?

One of the way is to create 3 threads and isssue "get" (read) in each of them (synchronously). 其中一种方法是创建3个线程并在每个线程中“获取”(读取)(同步)。 Wait for all 3 commands to complete and then combine the result. 等待所有3个命令完成,然后合并结果。

Does Jedis have a mechanism for issuing 3 "gets" (any command for that matter) asynchronously, with a callback feature? Jedis是否有一种机制可以异步发出3个“获取”(任何命令),具有回调功能?


I have 3 different Redis instances. 我有3个不同的Redis实例。 So do you suggest to use "ShardedJedisPipeline" (jedis/tests/ShardedJedisPipelineTest.java) for interacting with these Redis instances in parallel? 那么你建议使用“ShardedJedisPipeline”(jedis / tests / ShardedJedisPipelineTest.java)并行处理这些Redis实例吗?

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). 普通的Jedis管道(jedis / tests / PipeliningTest.java),只是向单个Redis实例发送多个命令,因此它们在Redis服务器上一个接一个地执行(并且最后的所有响应都可用)。

So I assume I have to use "ShardedJedisPipeline". 所以我假设我必须使用“ShardedJedisPipeline”。 But there are two limitations to this: 1. I want to execute Lua script ie "eval" on 3 Redis instances in parallel. 但是这有两个限制:1。我想在3个Redis实例上并行执行Lua脚本,即“eval”。 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. 2.我不想要分片(Jedis使用的一些散列算法)来分发数据,或者自己(使用其算法)从实例读取数据。 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. 所以我希望能够指定,记录应存储在哪个redis实例中,并相应地从哪里读取。 keyTags seems to provide this mechanism but not sure how to use this with "eval". keyTags似乎提供了这种机制,但不确定如何将其与“eval”一起使用。

You can use pipeline as mentioned. 你可以使用上面提到的管道。 AsyncJedis is a work is progress and will be released with the next version of Jedis. AsyncJedis是一项工作进展,将与下一版本的Jedis一起发布。 It will be based on netty and will be compatible with vert.x 它将基于netty并与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 到2015年2月,Jedis显然不支持在一个redis实例上进行Async操作,因为你需要: 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. 在我的案例中,我会做的是继续3个主题并继续使用Futures和Executor Service,如上面提到的@Xorlev。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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