dongmeixi5311 2016-12-09 05:30
浏览 352

使用不带WATCH的go-redis包实现流水线和事务到Redis集群

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

  • 写回答

1条回答 默认 最新

  • dongzha5934 2016-12-09 14:35
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化