{"record":{"id":"06bbc83c3b059c22","repo":"redis/redis-rb","slug":"command-to-s-upcase-cannot-be-used-in-redis-d","errorCode":null,"errorMessage":"#{@command.to_s.upcase} 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":"#(.+?) 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":1527,"sourceCode":"    end\n\n    def key_tag(key)\n      key = key.to_s\n      key[@tag, 1] if key.match?(@tag)\n    end\n\n    def ensure_same_node(command, keys)\n      all = true\n\n      tags = keys.map do |key|\n        tag = key_tag(key)\n        all = false unless tag\n        tag\n      end\n\n      if (all && tags.uniq.size != 1) || (!all && keys.uniq.size != 1)\n        # Not 1 unique tag or not 1 unique key\n        raise CannotDistribute, command\n      end\n\n      yield(node_for(keys.first))\n    end\n  end\nend\n","sourceCodeStart":1509,"sourceCodeEnd":1534,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/distributed.rb#L1509-L1534","documentation":"Error \"#{@command.to_s.upcase} 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:1527 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not call the reported command on Redis::Distributed; it involves multiple keys that must live on the same server.","Call the command on the specific node that owns the keys, or use Redis::Cluster where the server enforces slot co-location."],"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"}