exceptions.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. "Core exceptions raised by the Redis client"
  2. class RedisError(Exception):
  3. pass
  4. class ConnectionError(RedisError):
  5. pass
  6. class TimeoutError(RedisError):
  7. pass
  8. class AuthenticationError(ConnectionError):
  9. pass
  10. class AuthorizationError(ConnectionError):
  11. pass
  12. class BusyLoadingError(ConnectionError):
  13. pass
  14. class InvalidResponse(RedisError):
  15. pass
  16. class ResponseError(RedisError):
  17. pass
  18. class DataError(RedisError):
  19. pass
  20. class PubSubError(RedisError):
  21. pass
  22. class WatchError(RedisError):
  23. pass
  24. class NoScriptError(ResponseError):
  25. pass
  26. class OutOfMemoryError(ResponseError):
  27. """
  28. Indicates the database is full. Can only occur when either:
  29. * Redis maxmemory-policy=noeviction
  30. * Redis maxmemory-policy=volatile* and there are no evictable keys
  31. For more information see `Memory optimization in Redis <https://redis.io/docs/management/optimization/memory-optimization/#memory-allocation>`_. # noqa
  32. """
  33. pass
  34. class ExecAbortError(ResponseError):
  35. pass
  36. class ReadOnlyError(ResponseError):
  37. pass
  38. class NoPermissionError(ResponseError):
  39. pass
  40. class ModuleError(ResponseError):
  41. pass
  42. class LockError(RedisError, ValueError):
  43. "Errors acquiring or releasing a lock"
  44. # NOTE: For backwards compatibility, this class derives from ValueError.
  45. # This was originally chosen to behave like threading.Lock.
  46. pass
  47. class LockNotOwnedError(LockError):
  48. "Error trying to extend or release a lock that is (no longer) owned"
  49. pass
  50. class ChildDeadlockedError(Exception):
  51. "Error indicating that a child process is deadlocked after a fork()"
  52. pass
  53. class AuthenticationWrongNumberOfArgsError(ResponseError):
  54. """
  55. An error to indicate that the wrong number of args
  56. were sent to the AUTH command
  57. """
  58. pass
  59. class RedisClusterException(Exception):
  60. """
  61. Base exception for the RedisCluster client
  62. """
  63. pass
  64. class ClusterError(RedisError):
  65. """
  66. Cluster errors occurred multiple times, resulting in an exhaustion of the
  67. command execution TTL
  68. """
  69. pass
  70. class ClusterDownError(ClusterError, ResponseError):
  71. """
  72. Error indicated CLUSTERDOWN error received from cluster.
  73. By default Redis Cluster nodes stop accepting queries if they detect there
  74. is at least a hash slot uncovered (no available node is serving it).
  75. This way if the cluster is partially down (for example a range of hash
  76. slots are no longer covered) the entire cluster eventually becomes
  77. unavailable. It automatically returns available as soon as all the slots
  78. are covered again.
  79. """
  80. def __init__(self, resp):
  81. self.args = (resp,)
  82. self.message = resp
  83. class AskError(ResponseError):
  84. """
  85. Error indicated ASK error received from cluster.
  86. When a slot is set as MIGRATING, the node will accept all queries that
  87. pertain to this hash slot, but only if the key in question exists,
  88. otherwise the query is forwarded using a -ASK redirection to the node that
  89. is target of the migration.
  90. src node: MIGRATING to dst node
  91. get > ASK error
  92. ask dst node > ASKING command
  93. dst node: IMPORTING from src node
  94. asking command only affects next command
  95. any op will be allowed after asking command
  96. """
  97. def __init__(self, resp):
  98. """should only redirect to master node"""
  99. self.args = (resp,)
  100. self.message = resp
  101. slot_id, new_node = resp.split(" ")
  102. host, port = new_node.rsplit(":", 1)
  103. self.slot_id = int(slot_id)
  104. self.node_addr = self.host, self.port = host, int(port)
  105. class TryAgainError(ResponseError):
  106. """
  107. Error indicated TRYAGAIN error received from cluster.
  108. Operations on keys that don't exist or are - during resharding - split
  109. between the source and destination nodes, will generate a -TRYAGAIN error.
  110. """
  111. def __init__(self, *args, **kwargs):
  112. pass
  113. class ClusterCrossSlotError(ResponseError):
  114. """
  115. Error indicated CROSSSLOT error received from cluster.
  116. A CROSSSLOT error is generated when keys in a request don't hash to the
  117. same slot.
  118. """
  119. message = "Keys in request don't hash to the same slot"
  120. class MovedError(AskError):
  121. """
  122. Error indicated MOVED error received from cluster.
  123. A request sent to a node that doesn't serve this key will be replayed with
  124. a MOVED error that points to the correct node.
  125. """
  126. pass
  127. class MasterDownError(ClusterDownError):
  128. """
  129. Error indicated MASTERDOWN error received from cluster.
  130. Link with MASTER is down and replica-serve-stale-data is set to 'no'.
  131. """
  132. pass
  133. class SlotNotCoveredError(RedisClusterException):
  134. """
  135. This error only happens in the case where the connection pool will try to
  136. fetch what node that is covered by a given slot.
  137. If this error is raised the client should drop the current node layout and
  138. attempt to reconnect and refresh the node layout again
  139. """
  140. pass
  141. class MaxConnectionsError(ConnectionError):
  142. ...