简体   繁体   中英

Implementing pipelining and transaction both to a redis cluster using go-redis package without WATCH

My requirement is to implement pipelined transactions connecting to a redis cluster using go.I am using go-redis package which supports redis cluster,pipeling and transactions.How do I implement pipelined transactions without using WATCH key in go-redis package. I also looked at Tx.Pipeline() in the package.Is WATCH key necessary while implementing transaction

You will probably experience unhappy results with a combination of pipeline, transactions (MULTI/EXEC), and Cluster. In Redis Cluster you will be talking to multiple servers. This matters here because both pipelining and MULTI/EXEC are single-node oriented commands.

Pipelining is essentially queueing up a bunch of commands and shipping them as a single network call to the server. If your commands need to go to different cluster nodes, that won't work as you can't use a single network send to send to multiple nodes.

Similarly MULTI only exists within the node it was sent to, not cluster-wide. Thus, if your commands in the multi/exec access keys on different nodes, you will not have reliable transactions.

How that manifests is unknown because it depends on the client library and any checks it makes such as how it handles a redirect during a transaction block.

Ultimately, however, if you absolutely need pipelined multi/exec you will either need to ensure all keys are on one node by using Redis' "hashtag" method; use client-side code to check where all the keys are, raising an error if not on the same node while also hoping that a key doesn't been moved between the check and the command execution; or not use cluster. In the first two cases you will want to use WATCH to specify the keys to be used, thus giving you a chance at detecting a slot change as well as detecting different-node conditions.

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