1from __future__ import annotations
2
3from json import JSONDecoder, JSONEncoder
4from typing import TYPE_CHECKING
5
6if TYPE_CHECKING:
7 from .bf import (
8 AsyncBFBloom,
9 AsyncCFBloom,
10 AsyncCMSBloom,
11 AsyncTDigestBloom,
12 AsyncTOPKBloom,
13 BFBloom,
14 CFBloom,
15 CMSBloom,
16 TDigestBloom,
17 TOPKBloom,
18 )
19 from .json import JSON, AsyncJSON
20 from .search import AsyncSearch, Search
21 from .timeseries import AsyncTimeSeries, TimeSeries
22 from .vectorset import AsyncVectorSet, VectorSet
23
24
25class RedisModuleCommands:
26 """This class contains the wrapper functions to bring supported redis
27 modules into the command namespace.
28 """
29
30 def json(self, encoder=JSONEncoder(), decoder=JSONDecoder()) -> JSON:
31 """Access the json namespace, providing support for redis json."""
32
33 from .json import JSON
34
35 jj = JSON(client=self, encoder=encoder, decoder=decoder)
36 return jj
37
38 def ft(self, index_name="idx") -> Search:
39 """Access the search namespace, providing support for redis search."""
40
41 from .search import Search
42
43 s = Search(client=self, index_name=index_name)
44 return s
45
46 def ts(self) -> TimeSeries:
47 """Access the timeseries namespace, providing support for
48 redis timeseries data.
49 """
50
51 from .timeseries import TimeSeries
52
53 s = TimeSeries(client=self)
54 return s
55
56 def bf(self) -> BFBloom:
57 """Access the bloom namespace."""
58
59 from .bf import BFBloom
60
61 bf = BFBloom(client=self)
62 return bf
63
64 def cf(self) -> CFBloom:
65 """Access the bloom namespace."""
66
67 from .bf import CFBloom
68
69 cf = CFBloom(client=self)
70 return cf
71
72 def cms(self) -> CMSBloom:
73 """Access the bloom namespace."""
74
75 from .bf import CMSBloom
76
77 cms = CMSBloom(client=self)
78 return cms
79
80 def topk(self) -> TOPKBloom:
81 """Access the bloom namespace."""
82
83 from .bf import TOPKBloom
84
85 topk = TOPKBloom(client=self)
86 return topk
87
88 def tdigest(self) -> TDigestBloom:
89 """Access the bloom namespace."""
90
91 from .bf import TDigestBloom
92
93 tdigest = TDigestBloom(client=self)
94 return tdigest
95
96 def vset(self) -> VectorSet:
97 """Access the VectorSet commands namespace."""
98
99 from .vectorset import VectorSet
100
101 vset = VectorSet(client=self)
102 return vset
103
104
105class AsyncRedisModuleCommands(RedisModuleCommands):
106 def json(self, encoder=JSONEncoder(), decoder=JSONDecoder()) -> AsyncJSON:
107 """Access the json namespace, providing support for redis json."""
108
109 from .json import AsyncJSON
110
111 jj = AsyncJSON(client=self, encoder=encoder, decoder=decoder)
112 return jj
113
114 def ft(self, index_name="idx") -> AsyncSearch:
115 """Access the search namespace, providing support for redis search."""
116
117 from .search import AsyncSearch
118
119 s = AsyncSearch(client=self, index_name=index_name)
120 return s
121
122 def ts(self) -> AsyncTimeSeries:
123 """Access the timeseries namespace, providing support for
124 redis timeseries data.
125 """
126
127 from .timeseries import AsyncTimeSeries
128
129 s = AsyncTimeSeries(client=self)
130 return s
131
132 def bf(self) -> AsyncBFBloom:
133 """Access the bloom namespace."""
134
135 from .bf import AsyncBFBloom
136
137 bf = AsyncBFBloom(client=self)
138 return bf
139
140 def cf(self) -> AsyncCFBloom:
141 """Access the bloom namespace."""
142
143 from .bf import AsyncCFBloom
144
145 cf = AsyncCFBloom(client=self)
146 return cf
147
148 def cms(self) -> AsyncCMSBloom:
149 """Access the bloom namespace."""
150
151 from .bf import AsyncCMSBloom
152
153 cms = AsyncCMSBloom(client=self)
154 return cms
155
156 def topk(self) -> AsyncTOPKBloom:
157 """Access the bloom namespace."""
158
159 from .bf import AsyncTOPKBloom
160
161 topk = AsyncTOPKBloom(client=self)
162 return topk
163
164 def tdigest(self) -> AsyncTDigestBloom:
165 """Access the bloom namespace."""
166
167 from .bf import AsyncTDigestBloom
168
169 tdigest = AsyncTDigestBloom(client=self)
170 return tdigest
171
172 def vset(self) -> AsyncVectorSet:
173 """Access the VectorSet commands namespace."""
174
175 from .vectorset import AsyncVectorSet
176
177 vset = AsyncVectorSet(client=self)
178 return vset