{"record":{"id":"5555bb79d698f039","repo":"redis/redis-rb","slug":"discard-cannot-be-used-in-redis-distributed-becau","errorCode":null,"errorMessage":"DISCARD 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":"DISCARD 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":1346,"sourceCode":"    # 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\n      @watch_key = nil\n      result\n    end\n\n    # Control remote script registry.\n    def script(subcommand, *args)\n      on_each_node(:script, subcommand, *args)\n    end\n\n    # Set one or more contiguous values starting at an index in an array.\n    def arset(key, index, *values)\n      node_for(key).arset(key, index, *values)\n    end\n\n    # Get the value at an index in an array.\n    def arget(key, index)","sourceCodeStart":1328,"sourceCodeEnd":1364,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/distributed.rb#L1328-L1364","documentation":"Error \"DISCARD 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:1346 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not call discard on Redis::Distributed; transactions are not supported across shards.","Restructure the code to avoid MULTI/DISCARD, or run it against a single-node connection."],"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"}