summaryrefslogtreecommitdiff
path: root/redis/exceptions.py
diff options
context:
space:
mode:
authorBar Shaul <88437685+barshaul@users.noreply.github.com>2021-11-25 14:15:24 +0200
committerGitHub <noreply@github.com>2021-11-25 14:15:24 +0200
commit9db1eec71b443b8e7e74ff503bae651dc6edf411 (patch)
treece23ac6f923df54676349603f4e5551dfc801057 /redis/exceptions.py
parent021d4ac0edaecedb9b83235700cc4699cb119ef1 (diff)
downloadredis-py-9db1eec71b443b8e7e74ff503bae651dc6edf411.tar.gz
Adding RedisCluster client to support Redis Cluster Mode (#1660)
Co-authored-by: Chayim <chayim@users.noreply.github.com> Co-authored-by: Anas <anas.el.amraoui@live.com>
Diffstat (limited to 'redis/exceptions.py')
-rw-r--r--redis/exceptions.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/redis/exceptions.py b/redis/exceptions.py
index 91eb3c7..eb6ecc2 100644
--- a/redis/exceptions.py
+++ b/redis/exceptions.py
@@ -84,3 +84,105 @@ class AuthenticationWrongNumberOfArgsError(ResponseError):
were sent to the AUTH command
"""
pass
+
+
+class RedisClusterException(Exception):
+ """
+ Base exception for the RedisCluster client
+ """
+ pass
+
+
+class ClusterError(RedisError):
+ """
+ Cluster errors occurred multiple times, resulting in an exhaustion of the
+ command execution TTL
+ """
+ pass
+
+
+class ClusterDownError(ClusterError, ResponseError):
+ """
+ Error indicated CLUSTERDOWN error received from cluster.
+ By default Redis Cluster nodes stop accepting queries if they detect there
+ is at least a hash slot uncovered (no available node is serving it).
+ This way if the cluster is partially down (for example a range of hash
+ slots are no longer covered) the entire cluster eventually becomes
+ unavailable. It automatically returns available as soon as all the slots
+ are covered again.
+ """
+ def __init__(self, resp):
+ self.args = (resp,)
+ self.message = resp
+
+
+class AskError(ResponseError):
+ """
+ Error indicated ASK error received from cluster.
+ When a slot is set as MIGRATING, the node will accept all queries that
+ pertain to this hash slot, but only if the key in question exists,
+ otherwise the query is forwarded using a -ASK redirection to the node that
+ is target of the migration.
+ src node: MIGRATING to dst node
+ get > ASK error
+ ask dst node > ASKING command
+ dst node: IMPORTING from src node
+ asking command only affects next command
+ any op will be allowed after asking command
+ """
+
+ def __init__(self, resp):
+ """should only redirect to master node"""
+ self.args = (resp,)
+ self.message = resp
+ slot_id, new_node = resp.split(' ')
+ host, port = new_node.rsplit(':', 1)
+ self.slot_id = int(slot_id)
+ self.node_addr = self.host, self.port = host, int(port)
+
+
+class TryAgainError(ResponseError):
+ """
+ Error indicated TRYAGAIN error received from cluster.
+ Operations on keys that don't exist or are - during resharding - split
+ between the source and destination nodes, will generate a -TRYAGAIN error.
+ """
+ def __init__(self, *args, **kwargs):
+ pass
+
+
+class ClusterCrossSlotError(ResponseError):
+ """
+ Error indicated CROSSSLOT error received from cluster.
+ A CROSSSLOT error is generated when keys in a request don't hash to the
+ same slot.
+ """
+ message = "Keys in request don't hash to the same slot"
+
+
+class MovedError(AskError):
+ """
+ Error indicated MOVED error received from cluster.
+ A request sent to a node that doesn't serve this key will be replayed with
+ a MOVED error that points to the correct node.
+ """
+ pass
+
+
+class MasterDownError(ClusterDownError):
+ """
+ Error indicated MASTERDOWN error received from cluster.
+ Link with MASTER is down and replica-serve-stale-data is set to 'no'.
+ """
+ pass
+
+
+class SlotNotCoveredError(RedisClusterException):
+ """
+ This error only happens in the case where the connection pool will try to
+ fetch what node that is covered by a given slot.
+
+ If this error is raised the client should drop the current node layout and
+ attempt to reconnect and refresh the node layout again
+ """
+ pass