Skip to content

Commit 460537c

Browse files
authored
Add missing redis modules and classes (#7676)
This adds asyncio support and support for redis.typing.
1 parent caaf0f1 commit 460537c

File tree

14 files changed

+901
-6
lines changed

14 files changed

+901
-6
lines changed

stubs/redis/@tests/stubtest_allowlist.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,28 @@ redis.sentinel.Sentinel.master_for
44
redis.sentinel.Sentinel.slave_for
55
redis.client.Pipeline.transaction # instance attribute has same name as superclass method
66
redis.ocsp # requires cryptography to be installed
7+
8+
# TypeAlias-related problems
9+
redis.asyncio.client.CommandStackT
10+
redis.asyncio.client.CommandT
11+
redis.asyncio.client.PubSubHandler
12+
redis.asyncio.connection.ExceptionMappingT
13+
14+
# Protocol-related problems
15+
redis.asyncio.client.AsyncPubsubWorkerExceptionHandler.__init__
16+
redis.asyncio.client.AsyncResponseCallbackProtocol.__init__
17+
redis.asyncio.client.PubsubWorkerExceptionHandler.__init__
18+
redis.asyncio.client.ResponseCallbackProtocol.__init__
19+
redis.asyncio.connection.AsyncConnectCallbackProtocol.__init__
20+
redis.asyncio.connection.ConnectCallbackProtocol.__init__
21+
redis.typing.CommandsProtocol.__init__
22+
23+
# unclear problems
24+
redis.Sentinel.master_for
25+
redis.Sentinel.slave_for
26+
redis.asyncio.Sentinel.master_for
27+
redis.asyncio.Sentinel.slave_for
28+
redis.asyncio.sentinel.Sentinel.master_for
29+
redis.asyncio.sentinel.Sentinel.slave_for
30+
redis.sentinel.Sentinel.master_for
31+
redis.sentinel.Sentinel.slave_for
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from redis.asyncio.client import Redis as Redis, StrictRedis as StrictRedis
2+
from redis.asyncio.connection import (
3+
BlockingConnectionPool as BlockingConnectionPool,
4+
Connection as Connection,
5+
ConnectionPool as ConnectionPool,
6+
SSLConnection as SSLConnection,
7+
UnixDomainSocketConnection as UnixDomainSocketConnection,
8+
)
9+
from redis.asyncio.sentinel import (
10+
Sentinel as Sentinel,
11+
SentinelConnectionPool as SentinelConnectionPool,
12+
SentinelManagedConnection as SentinelManagedConnection,
13+
SentinelManagedSSLConnection as SentinelManagedSSLConnection,
14+
)
15+
from redis.asyncio.utils import from_url as from_url
16+
from redis.exceptions import (
17+
AuthenticationError as AuthenticationError,
18+
AuthenticationWrongNumberOfArgsError as AuthenticationWrongNumberOfArgsError,
19+
BusyLoadingError as BusyLoadingError,
20+
ChildDeadlockedError as ChildDeadlockedError,
21+
ConnectionError as ConnectionError,
22+
DataError as DataError,
23+
InvalidResponse as InvalidResponse,
24+
PubSubError as PubSubError,
25+
ReadOnlyError as ReadOnlyError,
26+
RedisError as RedisError,
27+
ResponseError as ResponseError,
28+
TimeoutError as TimeoutError,
29+
WatchError as WatchError,
30+
)
31+
32+
__all__ = [
33+
"AuthenticationError",
34+
"AuthenticationWrongNumberOfArgsError",
35+
"BlockingConnectionPool",
36+
"BusyLoadingError",
37+
"ChildDeadlockedError",
38+
"Connection",
39+
"ConnectionError",
40+
"ConnectionPool",
41+
"DataError",
42+
"from_url",
43+
"InvalidResponse",
44+
"PubSubError",
45+
"ReadOnlyError",
46+
"Redis",
47+
"RedisError",
48+
"ResponseError",
49+
"Sentinel",
50+
"SentinelConnectionPool",
51+
"SentinelManagedConnection",
52+
"SentinelManagedSSLConnection",
53+
"SSLConnection",
54+
"StrictRedis",
55+
"TimeoutError",
56+
"UnixDomainSocketConnection",
57+
"WatchError",
58+
]

stubs/redis/redis/asyncio/client.pyi

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
from _typeshed import Self
2+
from collections.abc import AsyncIterator, Callable, Iterable, Mapping, MutableMapping
3+
from typing import Any, Awaitable, Generic, NoReturn, Protocol
4+
from typing_extensions import TypeAlias, TypedDict
5+
6+
from redis.asyncio.connection import Connection, ConnectionPool
7+
from redis.asyncio.lock import Lock
8+
from redis.asyncio.retry import Retry
9+
from redis.client import AbstractRedis, _StrType
10+
from redis.commands import AsyncCoreCommands, AsyncSentinelCommands, RedisModuleCommands
11+
from redis.typing import ChannelT, EncodableT, KeyT
12+
13+
PubSubHandler: TypeAlias = Callable[[dict[str, str]], Awaitable[None]]
14+
15+
class ResponseCallbackProtocol(Protocol):
16+
def __call__(self, response: Any, **kwargs): ...
17+
18+
class AsyncResponseCallbackProtocol(Protocol):
19+
async def __call__(self, response: Any, **kwargs): ...
20+
21+
ResponseCallbackT: TypeAlias = ResponseCallbackProtocol | AsyncResponseCallbackProtocol
22+
23+
class Redis(AbstractRedis, RedisModuleCommands, AsyncCoreCommands[_StrType], AsyncSentinelCommands, Generic[_StrType]):
24+
response_callbacks: MutableMapping[str | bytes, ResponseCallbackT]
25+
@classmethod
26+
def from_url(cls, url: str, **kwargs) -> Redis[Any]: ...
27+
auto_close_connection_pool: Any
28+
connection_pool: Any
29+
single_connection_client: Any
30+
connection: Any
31+
def __init__(
32+
self,
33+
*,
34+
host: str = ...,
35+
port: int = ...,
36+
db: str | int = ...,
37+
password: str | None = ...,
38+
socket_timeout: float | None = ...,
39+
socket_connect_timeout: float | None = ...,
40+
socket_keepalive: bool | None = ...,
41+
socket_keepalive_options: Mapping[int, int | bytes] | None = ...,
42+
connection_pool: ConnectionPool | None = ...,
43+
unix_socket_path: str | None = ...,
44+
encoding: str = ...,
45+
encoding_errors: str = ...,
46+
decode_responses: bool = ...,
47+
retry_on_timeout: bool = ...,
48+
ssl: bool = ...,
49+
ssl_keyfile: str | None = ...,
50+
ssl_certfile: str | None = ...,
51+
ssl_cert_reqs: str = ...,
52+
ssl_ca_certs: str | None = ...,
53+
ssl_ca_data: str | None = ...,
54+
ssl_check_hostname: bool = ...,
55+
max_connections: int | None = ...,
56+
single_connection_client: bool = ...,
57+
health_check_interval: int = ...,
58+
client_name: str | None = ...,
59+
username: str | None = ...,
60+
retry: Retry | None = ...,
61+
auto_close_connection_pool: bool = ...,
62+
) -> None: ...
63+
def __await__(self): ...
64+
async def initialize(self: Self) -> Self: ...
65+
def set_response_callback(self, command: str, callback: ResponseCallbackT): ...
66+
def load_external_module(self, funcname, func) -> None: ...
67+
def pipeline(self, transaction: bool = ..., shard_hint: str | None = ...) -> Pipeline[_StrType]: ...
68+
async def transaction(
69+
self,
70+
func: Callable[[Pipeline[_StrType]], Any | Awaitable[Any]],
71+
*watches: KeyT,
72+
shard_hint: str | None = ...,
73+
value_from_callable: bool = ...,
74+
watch_delay: float | None = ...,
75+
): ...
76+
def lock(
77+
self,
78+
name: KeyT,
79+
timeout: float | None = ...,
80+
sleep: float = ...,
81+
blocking_timeout: float | None = ...,
82+
lock_class: type[Lock] | None = ...,
83+
thread_local: bool = ...,
84+
) -> Lock: ...
85+
def pubsub(self, **kwargs) -> PubSub: ...
86+
def monitor(self) -> Monitor: ...
87+
def client(self) -> Redis[_StrType]: ...
88+
async def __aenter__(self: Self) -> Self: ...
89+
async def __aexit__(self, exc_type, exc_value, traceback) -> None: ...
90+
def __del__(self, _warnings: Any = ...) -> None: ...
91+
async def close(self, close_connection_pool: bool | None = ...) -> None: ...
92+
async def execute_command(self, *args, **options): ...
93+
async def parse_response(self, connection: Connection, command_name: str | bytes, **options): ...
94+
95+
StrictRedis = Redis
96+
97+
class MonitorCommandInfo(TypedDict):
98+
time: float
99+
db: int
100+
client_address: str
101+
client_port: str
102+
client_type: str
103+
command: str
104+
105+
class Monitor:
106+
monitor_re: Any
107+
command_re: Any
108+
connection_pool: Any
109+
connection: Any
110+
def __init__(self, connection_pool: ConnectionPool) -> None: ...
111+
async def connect(self) -> None: ...
112+
async def __aenter__(self): ...
113+
async def __aexit__(self, *args) -> None: ...
114+
async def next_command(self) -> MonitorCommandInfo: ...
115+
async def listen(self) -> AsyncIterator[MonitorCommandInfo]: ...
116+
117+
class PubSub:
118+
PUBLISH_MESSAGE_TYPES: Any
119+
UNSUBSCRIBE_MESSAGE_TYPES: Any
120+
HEALTH_CHECK_MESSAGE: str
121+
connection_pool: Any
122+
shard_hint: Any
123+
ignore_subscribe_messages: Any
124+
connection: Any
125+
encoder: Any
126+
health_check_response: Any
127+
channels: Any
128+
pending_unsubscribe_channels: Any
129+
patterns: Any
130+
pending_unsubscribe_patterns: Any
131+
def __init__(
132+
self,
133+
connection_pool: ConnectionPool,
134+
shard_hint: str | None = ...,
135+
ignore_subscribe_messages: bool = ...,
136+
encoder: Any | None = ...,
137+
) -> None: ...
138+
async def __aenter__(self): ...
139+
async def __aexit__(self, exc_type, exc_value, traceback) -> None: ...
140+
def __del__(self) -> None: ...
141+
async def reset(self) -> None: ...
142+
def close(self) -> Awaitable[NoReturn]: ...
143+
async def on_connect(self, connection: Connection): ...
144+
@property
145+
def subscribed(self): ...
146+
async def execute_command(self, *args: EncodableT): ...
147+
async def parse_response(self, block: bool = ..., timeout: float = ...): ...
148+
async def check_health(self) -> None: ...
149+
async def psubscribe(self, *args: ChannelT, **kwargs: PubSubHandler): ...
150+
def punsubscribe(self, *args: ChannelT) -> Awaitable[Any]: ...
151+
async def subscribe(self, *args: ChannelT, **kwargs: Callable[..., Any]): ...
152+
def unsubscribe(self, *args) -> Awaitable[Any]: ...
153+
async def listen(self) -> AsyncIterator[Any]: ...
154+
async def get_message(self, ignore_subscribe_messages: bool = ..., timeout: float = ...): ...
155+
def ping(self, message: Any | None = ...) -> Awaitable[Any]: ...
156+
async def handle_message(self, response, ignore_subscribe_messages: bool = ...): ...
157+
async def run(self, *, exception_handler: PSWorkerThreadExcHandlerT | None = ..., poll_timeout: float = ...) -> None: ...
158+
159+
class PubsubWorkerExceptionHandler(Protocol):
160+
def __call__(self, e: BaseException, pubsub: PubSub): ...
161+
162+
class AsyncPubsubWorkerExceptionHandler(Protocol):
163+
async def __call__(self, e: BaseException, pubsub: PubSub): ...
164+
165+
PSWorkerThreadExcHandlerT: TypeAlias = PubsubWorkerExceptionHandler | AsyncPubsubWorkerExceptionHandler
166+
CommandT: TypeAlias = tuple[tuple[str | bytes, ...], Mapping[str, Any]]
167+
CommandStackT: TypeAlias = list[CommandT]
168+
169+
class Pipeline(Redis[_StrType], Generic[_StrType]):
170+
UNWATCH_COMMANDS: Any
171+
connection_pool: Any
172+
connection: Any
173+
response_callbacks: Any
174+
is_transaction: Any
175+
shard_hint: Any
176+
watching: bool
177+
command_stack: Any
178+
scripts: Any
179+
explicit_transaction: bool
180+
def __init__(
181+
self,
182+
connection_pool: ConnectionPool,
183+
response_callbacks: MutableMapping[str | bytes, ResponseCallbackT],
184+
transaction: bool,
185+
shard_hint: str | None,
186+
) -> None: ...
187+
async def __aenter__(self: Self) -> Self: ...
188+
async def __aexit__(self, exc_type, exc_value, traceback) -> None: ...
189+
def __await__(self): ...
190+
def __len__(self): ...
191+
def __bool__(self): ...
192+
async def reset(self) -> None: ... # type: ignore[override]
193+
def multi(self) -> None: ...
194+
def execute_command(self, *args, **kwargs) -> Pipeline[_StrType] | Awaitable[Pipeline[_StrType]]: ...
195+
async def immediate_execute_command(self, *args, **options): ...
196+
def pipeline_execute_command(self, *args, **options): ...
197+
def raise_first_error(self, commands: CommandStackT, response: Iterable[Any]): ...
198+
def annotate_exception(self, exception: Exception, number: int, command: Iterable[object]) -> None: ...
199+
async def parse_response(self, connection: Connection, command_name: str | bytes, **options): ...
200+
async def load_scripts(self) -> None: ...
201+
async def execute(self, raise_on_error: bool = ...): ...
202+
async def discard(self) -> None: ...
203+
async def watch(self, *names: KeyT): ...
204+
async def unwatch(self): ...

0 commit comments

Comments
 (0)