redis/redis-rb · error · Redis::Distributed::CannotDistribute
MSETNX cannot be used in Redis::Distributed because the keys
Error message
MSETNX 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 "MSETNX 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:336
end
# Set the value of a key, only if the key does not exist.
def setnx(key, value)
node_for(key).setnx(key, value)
end
# Set multiple keys to multiple values.
def mset(*)
raise CannotDistribute, :mset
end
def mapped_mset(_hash)
raise CannotDistribute, :mapped_mset
end
# Set multiple keys to multiple values, only if none of the keys exist.
def msetnx(*)
raise CannotDistribute, :msetnx
end
def mapped_msetnx(_hash)
raise CannotDistribute, :mapped_msetnx
end
# Get the value of a key.
def get(key)
node_for(key).get(key)
end
# Get the value of a key and delete it.
def getdel(key)
node_for(key).getdel(key)
end
# Get the value of a key and sets its time to live based on options.
def getex(key, **options)View on GitHub (pinned to 2ba9010b91)
Solutions
- Do not use msetnx on Redis::Distributed; the keys may hash to different servers and atomicity cannot be guaranteed.
- Use set with nx: true per key, accepting that the operation is no longer atomic across keys.
When it happens
Trigger: Thrown at lib/redis/distributed.rb:336 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/101157458dc6a3d5.
Report an issue: GitHub.