From 01df2a75e8d1bc10cc266c0f82f7cdb8ffa0a08f Mon Sep 17 00:00:00 2001 From: Denys Zhak Date: Fri, 3 Mar 2023 22:28:48 +0200 Subject: [PATCH 1/2] [redis] Stubs for AsyncRedisClusterCommands --- stubs/redis/redis/asyncio/cluster.pyi | 7 +++--- stubs/redis/redis/commands/__init__.pyi | 3 ++- stubs/redis/redis/commands/cluster.pyi | 29 ++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/stubs/redis/redis/asyncio/cluster.pyi b/stubs/redis/redis/asyncio/cluster.pyi index a5a3f5630805..ab51a82c58b7 100644 --- a/stubs/redis/redis/asyncio/cluster.pyi +++ b/stubs/redis/redis/asyncio/cluster.pyi @@ -9,8 +9,7 @@ from redis.asyncio.parser import CommandsParser from redis.client import AbstractRedis from redis.cluster import AbstractRedisCluster, LoadBalancer -# TODO: add AsyncRedisClusterCommands stubs -# from redis.commands import AsyncRedisClusterCommands +from redis.commands import AsyncRedisClusterCommands from redis.commands.core import _StrType from redis.credentials import CredentialProvider from redis.retry import Retry @@ -19,7 +18,7 @@ from redis.typing import AnyKeyT, EncodableT, KeyT # It uses `DefaultParser` in real life, but it is a dynamic base class. class ClusterParser(BaseParser): ... -class RedisCluster(AbstractRedis, AbstractRedisCluster, Generic[_StrType]): # TODO: AsyncRedisClusterCommands +class RedisCluster(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterCommands[_StrType], Generic[_StrType]): retry: Retry | None connection_kwargs: dict[str, Any] nodes_manager: NodesManager @@ -142,7 +141,7 @@ class NodesManager: async def initialize(self) -> None: ... async def close(self, attr: str = ...) -> None: ... -class ClusterPipeline(AbstractRedis, AbstractRedisCluster, Generic[_StrType]): # TODO: AsyncRedisClusterCommands +class ClusterPipeline(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterCommands[_StrType], Generic[_StrType]): def __init__(self, client: RedisCluster[_StrType]) -> None: ... async def initialize(self) -> Self: ... async def __aenter__(self) -> Self: ... diff --git a/stubs/redis/redis/commands/__init__.pyi b/stubs/redis/redis/commands/__init__.pyi index 4959ea0fdf15..2f357cb220a5 100644 --- a/stubs/redis/redis/commands/__init__.pyi +++ b/stubs/redis/redis/commands/__init__.pyi @@ -1,4 +1,4 @@ -from .cluster import RedisClusterCommands as RedisClusterCommands +from .cluster import RedisClusterCommands as RedisClusterCommands, AsyncRedisClusterCommands as AsyncRedisClusterCommands from .core import AsyncCoreCommands as AsyncCoreCommands, CoreCommands as CoreCommands from .helpers import list_or_args as list_or_args from .parser import CommandsParser as CommandsParser @@ -14,4 +14,5 @@ __all__ = [ "RedisModuleCommands", "AsyncSentinelCommands", "SentinelCommands", + "AsyncRedisClusterCommands", ] diff --git a/stubs/redis/redis/commands/cluster.pyi b/stubs/redis/redis/commands/cluster.pyi index 0a5981b01720..f1d50bf9dd17 100644 --- a/stubs/redis/redis/commands/cluster.pyi +++ b/stubs/redis/redis/commands/cluster.pyi @@ -1,7 +1,18 @@ from _typeshed import Incomplete from typing import Generic -from .core import ACLCommands, DataAccessCommands, ManagementCommands, PubSubCommands, _StrType +from .core import ( + ACLCommands, + AsyncACLCommands, + AsyncDataAccessCommands, + AsyncFunctionCommands, + AsyncManagementCommands, + AsyncScriptCommands, + DataAccessCommands, + ManagementCommands, + PubSubCommands, + _StrType, +) class ClusterMultiKeyCommands: def mget_nonatomic(self, keys, *args): ... @@ -11,11 +22,15 @@ class ClusterMultiKeyCommands: def touch(self, *keys): ... def unlink(self, *keys): ... +class AsyncClusterMultiKeyCommands(ClusterMultiKeyCommands): ... + class ClusterManagementCommands(ManagementCommands): def slaveof(self, *args, **kwargs) -> None: ... def replicaof(self, *args, **kwargs) -> None: ... def swapdb(self, *args, **kwargs) -> None: ... +class AsyncClusterManagementCommands(ClusterManagementCommands, AsyncManagementCommands): ... + class ClusterDataAccessCommands(DataAccessCommands[_StrType], Generic[_StrType]): def stralgo( self, @@ -30,6 +45,8 @@ class ClusterDataAccessCommands(DataAccessCommands[_StrType], Generic[_StrType]) **kwargs, ): ... +class AsyncClusterDataAccessCommands(ClusterDataAccessCommands[_StrType], AsyncDataAccessCommands[_StrType]): ... + class RedisClusterCommands( ClusterMultiKeyCommands, ClusterManagementCommands, @@ -59,3 +76,13 @@ class RedisClusterCommands( read_from_replicas: bool def readonly(self, target_nodes: Incomplete | None = ...): ... def readwrite(self, target_nodes: Incomplete | None = ...): ... + + +class AsyncRedisClusterCommands( + AsyncClusterMultiKeyCommands, + AsyncClusterManagementCommands, + AsyncACLCommands[_StrType], + AsyncClusterDataAccessCommands[_StrType], + AsyncScriptCommands[_StrType], + AsyncFunctionCommands, +): ... From 0de4389e8bf2b6f3aaecb2a2453076ab5e9149f4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 Mar 2023 20:35:07 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/redis/redis/asyncio/cluster.pyi | 1 - stubs/redis/redis/commands/__init__.pyi | 2 +- stubs/redis/redis/commands/cluster.pyi | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/stubs/redis/redis/asyncio/cluster.pyi b/stubs/redis/redis/asyncio/cluster.pyi index ab51a82c58b7..83cb5a05a418 100644 --- a/stubs/redis/redis/asyncio/cluster.pyi +++ b/stubs/redis/redis/asyncio/cluster.pyi @@ -8,7 +8,6 @@ from redis.asyncio.connection import BaseParser, Connection, Encoder from redis.asyncio.parser import CommandsParser from redis.client import AbstractRedis from redis.cluster import AbstractRedisCluster, LoadBalancer - from redis.commands import AsyncRedisClusterCommands from redis.commands.core import _StrType from redis.credentials import CredentialProvider diff --git a/stubs/redis/redis/commands/__init__.pyi b/stubs/redis/redis/commands/__init__.pyi index 2f357cb220a5..eb9c75b6ccba 100644 --- a/stubs/redis/redis/commands/__init__.pyi +++ b/stubs/redis/redis/commands/__init__.pyi @@ -1,4 +1,4 @@ -from .cluster import RedisClusterCommands as RedisClusterCommands, AsyncRedisClusterCommands as AsyncRedisClusterCommands +from .cluster import AsyncRedisClusterCommands as AsyncRedisClusterCommands, RedisClusterCommands as RedisClusterCommands from .core import AsyncCoreCommands as AsyncCoreCommands, CoreCommands as CoreCommands from .helpers import list_or_args as list_or_args from .parser import CommandsParser as CommandsParser diff --git a/stubs/redis/redis/commands/cluster.pyi b/stubs/redis/redis/commands/cluster.pyi index f1d50bf9dd17..47e0d5c96d68 100644 --- a/stubs/redis/redis/commands/cluster.pyi +++ b/stubs/redis/redis/commands/cluster.pyi @@ -77,7 +77,6 @@ class RedisClusterCommands( def readonly(self, target_nodes: Incomplete | None = ...): ... def readwrite(self, target_nodes: Incomplete | None = ...): ... - class AsyncRedisClusterCommands( AsyncClusterMultiKeyCommands, AsyncClusterManagementCommands,