Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial async redis cluster commands #12988

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions stubs/redis/redis/asyncio/cluster.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from _typeshed import Incomplete
from collections.abc import Awaitable, Callable, Mapping
from types import TracebackType
from typing import Any, Generic, TypeVar
from typing import Any, TypeVar
from typing_extensions import Self

from redis.asyncio.client import ResponseCallbackT
from redis.asyncio.connection import AbstractConnection, BaseParser, Connection, Encoder
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.exceptions import ResponseError
Expand All @@ -27,7 +25,7 @@
async def can_read_destructive(self) -> bool: ...
async def read_response(self, disable_decoding: bool = False) -> EncodableT | ResponseError | list[EncodableT] | None: ...

class RedisCluster(AbstractRedis, AbstractRedisCluster, Generic[_StrType]): # TODO: AsyncRedisClusterCommands
class RedisCluster(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterCommands):

Check failure on line 28 in stubs/redis/redis/asyncio/cluster.pyi

View workflow job for this annotation

GitHub Actions / Test typeshed with pyright (Linux, 3.12)

Expected type arguments for generic class "AsyncRedisClusterCommands" (reportMissingTypeArgument)
@classmethod
def from_url(
cls,
Expand Down Expand Up @@ -150,7 +148,7 @@
def get_connection_kwargs(self) -> dict[str, Any | None]: ...
def set_response_callback(self, command: str, callback: ResponseCallbackT) -> None: ...
async def execute_command(self, *args: EncodableT, **kwargs: Any) -> Any: ...
def pipeline(self, transaction: Any | None = None, shard_hint: Any | None = None) -> ClusterPipeline[_StrType]: ...

Check failure on line 151 in stubs/redis/redis/asyncio/cluster.pyi

View workflow job for this annotation

GitHub Actions / Test typeshed with pyright (Linux, 3.12)

Expected no type arguments for class "ClusterPipeline" (reportInvalidTypeArguments)

class ClusterNode:
host: str
Expand Down Expand Up @@ -203,8 +201,8 @@
async def close(self, attr: str = "nodes_cache") -> None: ...
def remap_host_port(self, host: str, port: int) -> tuple[str, int]: ...

class ClusterPipeline(AbstractRedis, AbstractRedisCluster, Generic[_StrType]): # TODO: AsyncRedisClusterCommands
class ClusterPipeline(AbstractRedis, AbstractRedisCluster, AsyncRedisClusterCommands):

Check failure on line 204 in stubs/redis/redis/asyncio/cluster.pyi

View workflow job for this annotation

GitHub Actions / Test typeshed with pyright (Linux, 3.12)

Expected type arguments for generic class "AsyncRedisClusterCommands" (reportMissingTypeArgument)
def __init__(self, client: RedisCluster[_StrType]) -> None: ...

Check failure on line 205 in stubs/redis/redis/asyncio/cluster.pyi

View workflow job for this annotation

GitHub Actions / Test typeshed with pyright (Linux, 3.12)

Expected no type arguments for class "RedisCluster" (reportInvalidTypeArguments)
async def initialize(self) -> Self: ...
async def __aenter__(self) -> Self: ...
async def __aexit__(
Expand Down
3 changes: 2 additions & 1 deletion stubs/redis/redis/commands/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .cluster import RedisClusterCommands as RedisClusterCommands
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
Expand All @@ -14,4 +14,5 @@ __all__ = [
"RedisModuleCommands",
"AsyncSentinelCommands",
"SentinelCommands",
"AsyncRedisClusterCommands",
]
46 changes: 45 additions & 1 deletion stubs/redis/redis/commands/cluster.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
from _typeshed import Incomplete
from typing import NoReturn

from .core import ACLCommands, DataAccessCommands, ManagementCommands, PubSubCommands, _StrType
from .core import (
ACLCommands,
AsyncDataAccessCommands,
AsyncManagementCommands,
AsyncScriptCommands,
DataAccessCommands,
FunctionCommands,
GearsCommands,
ManagementCommands,
ModuleCommands,
PubSubCommands,
_StrType,
)
from .redismodules import AsyncRedisModuleCommands

class ClusterMultiKeyCommands:
def mget_nonatomic(self, keys, *args): ...
Expand Down Expand Up @@ -58,3 +71,34 @@ class RedisClusterCommands(
read_from_replicas: bool
def readonly(self, target_nodes: Incomplete | None = None): ...
def readwrite(self, target_nodes: Incomplete | None = None): ...

class AsyncClusterMultiKeyCommands(ClusterMultiKeyCommands):
async def mget_nonatomic(self, keys, *args): ...
async def mset_nonatomic(self, mapping): ...

class AsyncClusterManagementCommands(ClusterManagementCommands, AsyncManagementCommands):
async def cluster_delslots(self, *slots): ...

class AsyncClusterDataAccessCommands(ClusterDataAccessCommands[_StrType], AsyncDataAccessCommands[_StrType]):
async def scan_iter(self, match, count, _type, **kwargs): ...

AsyncACLCommands = ACLCommands

AsyncFunctionCommands = FunctionCommands

AsyncGearsCommands = GearsCommands

class AsyncModuleCommands(ModuleCommands):
async def command_info(self) -> None: ...

class AsyncRedisClusterCommands(
AsyncClusterMultiKeyCommands,
AsyncClusterManagementCommands,
AsyncACLCommands,
AsyncClusterDataAccessCommands[_StrType],
AsyncScriptCommands[_StrType],
AsyncFunctionCommands,
AsyncGearsCommands,
AsyncModuleCommands,
AsyncRedisModuleCommands,
): ...
8 changes: 8 additions & 0 deletions stubs/redis/redis/commands/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,14 @@ class GeoCommands:
storedist: bool = False,
): ...

class GearsCommands:
def tfunction_load(self, lib_code, replace, config): ...
def tfunction_delete(self, lib_name: str): ...
def tfunction_list(self, with_code, verbose, lib_name): ...
def _tfcall(self, lib_name, func_name, keys, _async, *args): ...
def tfcall(self, lib_name, func_name, keys, *args): ...
def tfcall_async(self, lib_name: str, func_name: str, keys, *args): ...

class AsyncGeoCommands:
async def geoadd(self, name, values, nx: bool = False, xx: bool = False, ch: bool = False): ...
async def geodist(self, name, place1, place2, unit: Incomplete | None = None): ...
Expand Down
12 changes: 11 additions & 1 deletion stubs/redis/redis/commands/graph/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from .commands import GraphCommands as GraphCommands
from .commands import AsyncGraphCommands as AsyncGraphCommands, GraphCommands as GraphCommands
from .edge import Edge as Edge
from .node import Node as Node
from .path import Path as Path
Expand All @@ -24,3 +24,13 @@ class Graph(GraphCommands):
def labels(self): ...
def relationship_types(self): ...
def property_keys(self): ...

class AsyncGraph(Graph, AsyncGraphCommands):
async def _refresh_labels(self): ...
async def _refresh_attributes(self): ...
async def _refresh_relations(self): ...
async def get_label(self, idx): ...
async def call_procedure(self, procedure, *args, read_only: bool = False, **kwagrs): ...
async def labels(self): ...
async def property_keys(self): ...
async def relationship_types(self): ...
13 changes: 13 additions & 0 deletions stubs/redis/redis/commands/graph/commands.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ class GraphCommands:
def slowlog(self): ...
def config(self, name, value: Incomplete | None = None, set: bool = False): ...
def list_keys(self): ...

class AsyncGraphCommands(GraphCommands):
async def query(
self,
q,
params: Incomplete | None = None,
timeout: Incomplete | None = None,
read_only: bool = False,
profile: bool = False,
): ...
async def execution_plan(self, query, params: Incomplete | None = None): ...
async def explain(self, query, params: Incomplete | None = None): ...
async def flush(self): ...
7 changes: 6 additions & 1 deletion stubs/redis/redis/commands/redismodules.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .graph import AsyncGraph
from .json import JSON
from .search import Search
from .search import AsyncSearch, Search
from .timeseries import TimeSeries

class RedisModuleCommands:
Expand All @@ -12,3 +13,7 @@ class RedisModuleCommands:
def topk(self): ...
def tdigest(self): ...
def graph(self, index_name: str = "idx"): ...

class AsyncRedisModuleCommands(RedisModuleCommands):
def ft(self, index_name: str = "idx") -> AsyncSearch: ...
def graph(self, index_name: str = "idx") -> AsyncGraph: ...
25 changes: 24 additions & 1 deletion stubs/redis/redis/commands/search/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from _typeshed import Incomplete

from .commands import SearchCommands
from ...asyncio.client import Pipeline as AsyncioPipeline
from ...client import Pipeline as SyncPipeline
from ...commands.core import _StrType
from .commands import AsyncSearchCommands, SearchCommands

class Search(SearchCommands):
class BatchIndexer:
Expand All @@ -20,3 +23,23 @@ class Search(SearchCommands):
def commit(self): ...

def __init__(self, client, index_name: str = "idx") -> None: ...

class Pipeline(SearchCommands, SyncPipeline[_StrType]): ...
class AsyncPipeline(AsyncSearchCommands, AsyncioPipeline[_StrType], Pipeline[_StrType]): ...

class AsyncSearch(Search, AsyncSearchCommands):
class BatchIndexer(Search.BatchIndexer):
async def add_document(
self,
doc_id,
nosave: bool = False,
score: float = 1.0,
payload: Incomplete | None = None,
replace: bool = False,
partial: bool = False,
no_create: bool = False,
**fields,
): ...
async def commit(self): ...

def pipeline(self, transaction: bool = True, shard_hint: Incomplete | None = None): ...
13 changes: 13 additions & 0 deletions stubs/redis/redis/commands/search/commands.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,16 @@ class SearchCommands:
def sugget(self, key, prefix, fuzzy: bool = False, num: int = 10, with_scores: bool = False, with_payloads: bool = False): ...
def synupdate(self, groupid, skipinitial: bool = False, *terms): ...
def syndump(self): ...

class AsyncSearchCommands(SearchCommands):
async def info(self): ...
async def search(self, query, query_params): ...
async def aggregate(self, query, query_params): ...
async def spellcheck(self, query, distance, include, exclude): ...
async def config_set(self, option, value): ...
async def config_get(self, option): ...
async def load_document(self, id): ...
async def sugadd(self, key, *suggestions, increment): ...
async def sugget(
self, key, prefix, fuzzy: bool = False, num: int = 10, with_scores: bool = False, with_payloads: bool = False
): ...
3 changes: 2 additions & 1 deletion stubs/redis/redis/typing.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Iterable
from datetime import datetime, timedelta
from typing import Any, Protocol, TypeVar
from typing import Any, Awaitable, Protocol, TypeVar, Union
from typing_extensions import TypeAlias

from redis.asyncio.connection import ConnectionPool as AsyncConnectionPool
Expand All @@ -24,6 +24,7 @@ GroupT: TypeAlias = _StringLikeT
ConsumerT: TypeAlias = _StringLikeT
StreamIdT: TypeAlias = int | _StringLikeT
ScriptTextT: TypeAlias = _StringLikeT
ResponseT: TypeAlias = Union[Awaitable[Any], Any]
TimeoutSecT: TypeAlias = int | float | _StringLikeT
AnyKeyT = TypeVar("AnyKeyT", bytes, str, memoryview) # noqa: Y001
AnyFieldT = TypeVar("AnyFieldT", bytes, str, memoryview) # noqa: Y001
Expand Down
Loading