Skip to content

Adding return types for the RedisModuleCommands class #3632

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

Merged
merged 2 commits into from
May 8, 2025
Merged
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
30 changes: 20 additions & 10 deletions redis/commands/redismodules.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
from __future__ import annotations

from json import JSONDecoder, JSONEncoder
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from .bf import BFBloom, CFBloom, CMSBloom, TDigestBloom, TOPKBloom
from .json import JSON
from .search import AsyncSearch, Search
from .timeseries import TimeSeries
from .vectorset import VectorSet


class RedisModuleCommands:
"""This class contains the wrapper functions to bring supported redis
modules into the command namespace.
"""

def json(self, encoder=JSONEncoder(), decoder=JSONDecoder()):
def json(self, encoder=JSONEncoder(), decoder=JSONDecoder()) -> JSON:
"""Access the json namespace, providing support for redis json."""

from .json import JSON

jj = JSON(client=self, encoder=encoder, decoder=decoder)
return jj

def ft(self, index_name="idx"):
def ft(self, index_name="idx") -> Search:
"""Access the search namespace, providing support for redis search."""

from .search import Search

s = Search(client=self, index_name=index_name)
return s

def ts(self):
def ts(self) -> TimeSeries:
"""Access the timeseries namespace, providing support for
redis timeseries data.
"""
Expand All @@ -32,47 +42,47 @@ def ts(self):
s = TimeSeries(client=self)
return s

def bf(self):
def bf(self) -> BFBloom:
"""Access the bloom namespace."""

from .bf import BFBloom

bf = BFBloom(client=self)
return bf

def cf(self):
def cf(self) -> CFBloom:
"""Access the bloom namespace."""

from .bf import CFBloom

cf = CFBloom(client=self)
return cf

def cms(self):
def cms(self) -> CMSBloom:
"""Access the bloom namespace."""

from .bf import CMSBloom

cms = CMSBloom(client=self)
return cms

def topk(self):
def topk(self) -> TOPKBloom:
"""Access the bloom namespace."""

from .bf import TOPKBloom

topk = TOPKBloom(client=self)
return topk

def tdigest(self):
def tdigest(self) -> TDigestBloom:
"""Access the bloom namespace."""

from .bf import TDigestBloom

tdigest = TDigestBloom(client=self)
return tdigest

def vset(self):
def vset(self) -> VectorSet:
"""Access the VectorSet commands namespace."""

from .vectorset import VectorSet
Expand All @@ -82,7 +92,7 @@ def vset(self):


class AsyncRedisModuleCommands(RedisModuleCommands):
def ft(self, index_name="idx"):
def ft(self, index_name="idx") -> AsyncSearch:
"""Access the search namespace, providing support for redis search."""

from .search import AsyncSearch
Expand Down
Loading