txredisapi.pyi 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright 2020 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Contains *incomplete* type hints for txredisapi.
  15. """
  16. from typing import Any, List, Optional, Type, Union
  17. from twisted.internet import protocol
  18. from twisted.internet.defer import Deferred
  19. class RedisProtocol(protocol.Protocol):
  20. def publish(self, channel: str, message: bytes) -> "Deferred[None]": ...
  21. def ping(self) -> "Deferred[None]": ...
  22. def set(
  23. self,
  24. key: str,
  25. value: Any,
  26. expire: Optional[int] = None,
  27. pexpire: Optional[int] = None,
  28. only_if_not_exists: bool = False,
  29. only_if_exists: bool = False,
  30. ) -> "Deferred[None]": ...
  31. def get(self, key: str) -> "Deferred[Any]": ...
  32. class SubscriberProtocol(RedisProtocol):
  33. def __init__(self, *args, **kwargs): ...
  34. password: Optional[str]
  35. def subscribe(self, channels: Union[str, List[str]]): ...
  36. def connectionMade(self): ...
  37. def connectionLost(self, reason): ...
  38. def lazyConnection(
  39. host: str = ...,
  40. port: int = ...,
  41. dbid: Optional[int] = ...,
  42. reconnect: bool = ...,
  43. charset: str = ...,
  44. password: Optional[str] = ...,
  45. connectTimeout: Optional[int] = ...,
  46. replyTimeout: Optional[int] = ...,
  47. convertNumbers: bool = ...,
  48. ) -> RedisProtocol: ...
  49. # ConnectionHandler doesn't actually inherit from RedisProtocol, but it proxies
  50. # most methods to it via ConnectionHandler.__getattr__.
  51. class ConnectionHandler(RedisProtocol):
  52. def disconnect(self) -> "Deferred[None]": ...
  53. class RedisFactory(protocol.ReconnectingClientFactory):
  54. continueTrying: bool
  55. handler: ConnectionHandler
  56. pool: List[RedisProtocol]
  57. replyTimeout: Optional[int]
  58. def __init__(
  59. self,
  60. uuid: str,
  61. dbid: Optional[int],
  62. poolsize: int,
  63. isLazy: bool = False,
  64. handler: Type = ConnectionHandler,
  65. charset: str = "utf-8",
  66. password: Optional[str] = None,
  67. replyTimeout: Optional[int] = None,
  68. convertNumbers: Optional[int] = True,
  69. ): ...
  70. def buildProtocol(self, addr) -> RedisProtocol: ...
  71. class SubscriberFactory(RedisFactory):
  72. def __init__(self) -> None: ...