图片解析应用
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.

66 lines
2.2 KiB

  1. # from __future__ import annotations
  2. from datetime import datetime, timedelta
  3. from typing import (
  4. TYPE_CHECKING,
  5. Any,
  6. Awaitable,
  7. Iterable,
  8. Mapping,
  9. Type,
  10. TypeVar,
  11. Union,
  12. )
  13. from redis.compat import Protocol
  14. if TYPE_CHECKING:
  15. from redis._parsers import Encoder
  16. from redis.asyncio.connection import ConnectionPool as AsyncConnectionPool
  17. from redis.connection import ConnectionPool
  18. Number = Union[int, float]
  19. EncodedT = Union[bytes, memoryview]
  20. DecodedT = Union[str, int, float]
  21. EncodableT = Union[EncodedT, DecodedT]
  22. AbsExpiryT = Union[int, datetime]
  23. ExpiryT = Union[int, timedelta]
  24. ZScoreBoundT = Union[float, str] # str allows for the [ or ( prefix
  25. BitfieldOffsetT = Union[int, str] # str allows for #x syntax
  26. _StringLikeT = Union[bytes, str, memoryview]
  27. KeyT = _StringLikeT # Main redis key space
  28. PatternT = _StringLikeT # Patterns matched against keys, fields etc
  29. FieldT = EncodableT # Fields within hash tables, streams and geo commands
  30. KeysT = Union[KeyT, Iterable[KeyT]]
  31. ResponseT = Union[Awaitable[Any], Any]
  32. ChannelT = _StringLikeT
  33. GroupT = _StringLikeT # Consumer group
  34. ConsumerT = _StringLikeT # Consumer name
  35. StreamIdT = Union[int, _StringLikeT]
  36. ScriptTextT = _StringLikeT
  37. TimeoutSecT = Union[int, float, _StringLikeT]
  38. # Mapping is not covariant in the key type, which prevents
  39. # Mapping[_StringLikeT, X] from accepting arguments of type Dict[str, X]. Using
  40. # a TypeVar instead of a Union allows mappings with any of the permitted types
  41. # to be passed. Care is needed if there is more than one such mapping in a
  42. # type signature because they will all be required to be the same key type.
  43. AnyKeyT = TypeVar("AnyKeyT", bytes, str, memoryview)
  44. AnyFieldT = TypeVar("AnyFieldT", bytes, str, memoryview)
  45. AnyChannelT = TypeVar("AnyChannelT", bytes, str, memoryview)
  46. ExceptionMappingT = Mapping[str, Union[Type[Exception], Mapping[str, Type[Exception]]]]
  47. class CommandsProtocol(Protocol):
  48. connection_pool: Union["AsyncConnectionPool", "ConnectionPool"]
  49. def execute_command(self, *args, **options):
  50. ...
  51. class ClusterCommandsProtocol(CommandsProtocol, Protocol):
  52. encoder: "Encoder"
  53. def execute_command(self, *args, **options) -> Union[Any, Awaitable]:
  54. ...