vtscop
vtscop

Reputation: 171

Redis command batch on a Redis Cluster

We are using StackExchange.Redis to access a regular Redis database. Now we want to setup that database as a cluster, so we are reviewing code to make sure that there are not MULTI or Lua scripts that may break because the key distribution across nodes.

There are no Lua scripts or MULTI but there is a lot of redis.GetDatabase().CreateBatch(). As far as I know, a batch is just sending the commands pipelined to Redis, but will this work with Redis Cluster?

After reading some documentation, I would say that each command in the batch will be handled separately and if the node redirects the client to another node for that particular command, it will be handled by the library itself. In fact, each command in the batch has its very own Task returned, so it should be OK. However there are some folks in the internet claiming the contrary : https://groups.google.com/forum/#!topic/redis-db/1wc9tJSprms

So can I expect batches to work properly in Redis Cluster?

Upvotes: 1

Views: 2590

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063864

It should work. Internally, RedisBatch.Execute splits the queued commands into per-destination groups (maintaining the original order per-group), and then flushes each separately; so it does consider the scenario and attempt to keep things together as much as possible to avoid packet fragmentation and interleaved messages, etc. If the keys involved means that this ends up talking to 3 different servers, then so be it. It will involve more packets than if you were only talking to one server, but then... you also end up with 3 server CPUs to process the work, so... both pros and cons. But fundamentally: yes, it should work.

Upvotes: 2

Related Questions