{"record":{"id":"5c026388e834e5c8","repo":"redis/redis-rb","slug":"multi-cannot-be-used-in-redis-distributed-because","errorCode":null,"errorMessage":"MULTI cannot be used in Redis::Distributed because the keys involved need to be on the same server or because we cannot guarantee that the operation will be atomic.","messagePattern":"MULTI cannot be used in Redis::Distributed because the keys involved need to be on the same server or because we cannot guarantee that the operation will be atomic\\.","errorType":"exception","errorClass":"Redis::Distributed::CannotDistribute","httpStatus":null,"severity":"error","filePath":"lib/redis/distributed.rb","lineNumber":1330,"sourceCode":"      end\n    end\n\n    # Forget about all watched keys.\n    def unwatch\n      raise CannotDistribute, :unwatch unless @watch_key\n\n      result = node_for(@watch_key).unwatch\n      @watch_key = nil\n      result\n    end\n\n    def pipelined\n      raise CannotDistribute, :pipelined\n    end\n\n    # Mark the start of a transaction block.\n    def multi(&block)\n      raise CannotDistribute, :multi unless @watch_key\n\n      node_for(@watch_key).multi(&block)\n    end\n\n    # Execute all commands issued after MULTI.\n    def exec\n      raise CannotDistribute, :exec unless @watch_key\n\n      result = node_for(@watch_key).exec\n      @watch_key = nil\n      result\n    end\n\n    # Discard all commands issued after MULTI.\n    def discard\n      raise CannotDistribute, :discard unless @watch_key\n\n      result = node_for(@watch_key).discard","sourceCodeStart":1312,"sourceCodeEnd":1348,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/distributed.rb#L1312-L1348","documentation":"Error \"MULTI cannot be used in Redis::Distributed because the keys involved need to be on the same server or because we cannot guarantee that the operation will be atomic.\" thrown in redis/redis-rb.","triggerScenarios":"Thrown at lib/redis/distributed.rb:1330 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not start a MULTI transaction on Redis::Distributed; commands may target different servers.","Run the transaction against a single Redis instance, or use Redis::Cluster for cross-slot transaction support."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2ba9010b91dab9e0fde1fbae3a9aae003f8bc307","analyzedAt":"2026-08-23T03:54:57.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}