{"record":{"id":"8dc5be91b3c42006","repo":"redis/redis-rb","slug":"migrate-cannot-be-used-in-redis-distributed-becau","errorCode":null,"errorMessage":"MIGRATE 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":"MIGRATE 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":184,"sourceCode":"\n    # Get the time to live (in milliseconds) for a key.\n    def pttl(key)\n      node_for(key).pttl(key)\n    end\n\n    # Return a serialized version of the value stored at a key.\n    def dump(key)\n      node_for(key).dump(key)\n    end\n\n    # Create a key using the serialized value, previously obtained using DUMP.\n    def restore(key, ttl, serialized_value, **options)\n      node_for(key).restore(key, ttl, serialized_value, **options)\n    end\n\n    # Transfer a key from the connected instance to another instance.\n    def migrate(_key, _options)\n      raise CannotDistribute, :migrate\n    end\n\n    # Delete a key.\n    def del(*args)\n      args.flatten!(1)\n      keys_per_node = args.group_by { |key| node_for(key) }\n      keys_per_node.inject(0) do |sum, (node, keys)|\n        sum + node.del(*keys)\n      end\n    end\n\n    # Unlink keys.\n    def unlink(*args)\n      args.flatten!(1)\n      keys_per_node = args.group_by { |key| node_for(key) }\n      keys_per_node.inject(0) do |sum, (node, keys)|\n        sum + node.unlink(*keys)\n      end","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/distributed.rb#L166-L202","documentation":"Error \"MIGRATE 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:184 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not use migrate on Redis::Distributed; MIGRATE moves keys between servers which breaks client-side sharding assumptions.","Migrate keys manually by reading from the source node and writing to the target node."],"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"}