图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
5.1 KiB

  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. def __init__(self, message=None, lock_name=None):
  47. self.message = message
  48. self.lock_name = lock_name
  49. class LockNotOwnedError(LockError):
  50. "Error trying to extend or release a lock that is (no longer) owned"
  51. pass
  52. class ChildDeadlockedError(Exception):
  53. "Error indicating that a child process is deadlocked after a fork()"
  54. pass
  55. class AuthenticationWrongNumberOfArgsError(ResponseError):
  56. """
  57. An error to indicate that the wrong number of args
  58. were sent to the AUTH command
  59. """
  60. pass
  61. class RedisClusterException(Exception):
  62. """
  63. Base exception for the RedisCluster client
  64. """
  65. pass
  66. class ClusterError(RedisError):
  67. """
  68. Cluster errors occurred multiple times, resulting in an exhaustion of the
  69. command execution TTL
  70. """
  71. pass
  72. class ClusterDownError(ClusterError, ResponseError):
  73. """
  74. Error indicated CLUSTERDOWN error received from cluster.
  75. By default Redis Cluster nodes stop accepting queries if they detect there
  76. is at least a hash slot uncovered (no available node is serving it).
  77. This way if the cluster is partially down (for example a range of hash
  78. slots are no longer covered) the entire cluster eventually becomes
  79. unavailable. It automatically returns available as soon as all the slots
  80. are covered again.
  81. """
  82. def __init__(self, resp):
  83. self.args = (resp,)
  84. self.message = resp
  85. class AskError(ResponseError):
  86. """
  87. Error indicated ASK error received from cluster.
  88. When a slot is set as MIGRATING, the node will accept all queries that
  89. pertain to this hash slot, but only if the key in question exists,
  90. otherwise the query is forwarded using a -ASK redirection to the node that
  91. is target of the migration.
  92. src node: MIGRATING to dst node
  93. get > ASK error
  94. ask dst node > ASKING command
  95. dst node: IMPORTING from src node
  96. asking command only affects next command
  97. any op will be allowed after asking command
  98. """
  99. def __init__(self, resp):
  100. """should only redirect to master node"""
  101. self.args = (resp,)
  102. self.message = resp
  103. slot_id, new_node = resp.split(" ")
  104. host, port = new_node.rsplit(":", 1)
  105. self.slot_id = int(slot_id)
  106. self.node_addr = self.host, self.port = host, int(port)
  107. class TryAgainError(ResponseError):
  108. """
  109. Error indicated TRYAGAIN error received from cluster.
  110. Operations on keys that don't exist or are - during resharding - split
  111. between the source and destination nodes, will generate a -TRYAGAIN error.
  112. """
  113. def __init__(self, *args, **kwargs):
  114. pass
  115. class ClusterCrossSlotError(ResponseError):
  116. """
  117. Error indicated CROSSSLOT error received from cluster.
  118. A CROSSSLOT error is generated when keys in a request don't hash to the
  119. same slot.
  120. """
  121. message = "Keys in request don't hash to the same slot"
  122. class MovedError(AskError):
  123. """
  124. Error indicated MOVED error received from cluster.
  125. A request sent to a node that doesn't serve this key will be replayed with
  126. a MOVED error that points to the correct node.
  127. """
  128. pass
  129. class MasterDownError(ClusterDownError):
  130. """
  131. Error indicated MASTERDOWN error received from cluster.
  132. Link with MASTER is down and replica-serve-stale-data is set to 'no'.
  133. """
  134. pass
  135. class SlotNotCoveredError(RedisClusterException):
  136. """
  137. This error only happens in the case where the connection pool will try to
  138. fetch what node that is covered by a given slot.
  139. If this error is raised the client should drop the current node layout and
  140. attempt to reconnect and refresh the node layout again
  141. """
  142. pass
  143. class MaxConnectionsError(ConnectionError):
  144. ...