redis/redis-rb · error · Redis::Distributed::CannotDistribute

MULTI cannot be used in Redis::Distributed because the keys

Error message

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.

What it means

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.

Source

Thrown at lib/redis/distributed.rb:1330

      end
    end

    # Forget about all watched keys.
    def unwatch
      raise CannotDistribute, :unwatch unless @watch_key

      result = node_for(@watch_key).unwatch
      @watch_key = nil
      result
    end

    def pipelined
      raise CannotDistribute, :pipelined
    end

    # Mark the start of a transaction block.
    def multi(&block)
      raise CannotDistribute, :multi unless @watch_key

      node_for(@watch_key).multi(&block)
    end

    # Execute all commands issued after MULTI.
    def exec
      raise CannotDistribute, :exec unless @watch_key

      result = node_for(@watch_key).exec
      @watch_key = nil
      result
    end

    # Discard all commands issued after MULTI.
    def discard
      raise CannotDistribute, :discard unless @watch_key

      result = node_for(@watch_key).discard

View on GitHub (pinned to 2ba9010b91)

Solutions

  1. Do not start a MULTI transaction on Redis::Distributed; commands may target different servers.
  2. Run the transaction against a single Redis instance, or use Redis::Cluster for cross-slot transaction support.

When it happens

Trigger: Thrown at lib/redis/distributed.rb:1330 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of redis/redis-rb@2ba9010b91 (2026-08-23). Data as JSON: /api/errors/5c026388e834e5c8. Report an issue: GitHub.