Skip to content

Commit 573caef

Browse files
committed
Support redis-py 5 and 6
1 parent b9ce3d5 commit 573caef

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
make test-all
7979
8080
test:
81-
name: Python ${{ matrix.python-version }} - ${{ matrix.connection }} [redis ${{ matrix.redis-version }}]
81+
name: Python ${{ matrix.python-version }} - ${{ matrix.connection }} - redis-py ${{ matrix.redis-py-version }} [redis ${{ matrix.redis-version }}]
8282
runs-on: ubuntu-latest
8383
needs: service-tests
8484
env:
@@ -89,6 +89,7 @@ jobs:
8989
# 3.11 tests are run in the service-tests job
9090
python-version: ["3.9", "3.10", 3.12, 3.13]
9191
connection: ["hiredis", "plain"]
92+
redis-py-version: ["5.x", "6.x"]
9293
redis-version: ["6.2.6-v9", "latest", "8.0-M03"]
9394

9495
steps:
@@ -116,6 +117,14 @@ jobs:
116117
run: |
117118
poetry install --all-extras
118119
120+
- name: Install specific redis-py version
121+
run: |
122+
if [[ "${{ matrix.redis-py-version }}" == "5.x" ]]; then
123+
poetry add "redis>=5.0.0,<6.0.0"
124+
else
125+
poetry add "redis>=6.0.0,<7.0.0"
126+
fi
127+
119128
- name: Install hiredis if needed
120129
if: matrix.connection == 'hiredis'
121130
run: |
@@ -135,7 +144,7 @@ jobs:
135144
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
136145

137146
- name: Run tests
138-
if: matrix.connection == 'plain' && matrix.redis-version == 'latest'
147+
if: matrix.connection == 'plain' && matrix.redis-py-version == '6.x' && matrix.redis-version == 'latest'
139148
env:
140149
HF_HOME: ${{ github.workspace }}/hf_cache
141150
GCP_LOCATION: ${{ secrets.GCP_LOCATION }}
@@ -144,12 +153,12 @@ jobs:
144153
make test
145154
146155
- name: Run tests (alternate)
147-
if: matrix.connection != 'plain' || matrix.redis-version != 'latest'
156+
if: matrix.connection != 'plain' || matrix.redis-py-version != '6.x' || matrix.redis-version != 'latest'
148157
run: |
149158
make test
150159
151160
- name: Run notebooks
152-
if: matrix.connection == 'plain' && matrix.redis-version == 'latest'
161+
if: matrix.connection == 'plain' && matrix.redis-py-version == '6.x' && matrix.redis-version == 'latest'
153162
env:
154163
HF_HOME: ${{ github.workspace }}/hf_cache
155164
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ numpy = [
2626
{ version = ">=1.26.0,<3", python = ">=3.12" },
2727
]
2828
pyyaml = ">=5.4,<7.0"
29-
redis = "^6.0"
29+
redis = ">=5.0,<7.0"
3030
pydantic = "^2"
3131
tenacity = ">=8.2.2"
3232
ml-dtypes = ">=0.4.0,<1.0.0"

redisvl/index/index.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@
4545

4646
from redis.client import NEVER_DECODE
4747
from redis.commands.helpers import get_protocol_version # type: ignore
48-
from redis.commands.search.index_definition import IndexDefinition
48+
49+
# Redis 5.x compatibility (6 fixed the import path)
50+
try:
51+
from redis.commands.search.index_definition import ( # type: ignore[import-untyped]
52+
IndexDefinition,
53+
)
54+
except ModuleNotFoundError:
55+
from redis.commands.search.indexDefinition import IndexDefinition
4956

5057
# Need Result outside TYPE_CHECKING for cast
5158
from redis.commands.search.result import Result

redisvl/index/storage.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
# Add imports for Pipeline types
1818
from redis.asyncio.client import Pipeline as AsyncPipeline
1919
from redis.asyncio.cluster import ClusterPipeline as AsyncClusterPipeline
20-
from redis.commands.search.index_definition import IndexType
20+
21+
# Redis 5.x compatibility (6 fixed the import path)
22+
try:
23+
from redis.commands.search.index_definition import ( # type: ignore[import-untyped]
24+
IndexType,
25+
)
26+
except ModuleNotFoundError:
27+
from redis.commands.search.indexDefinition import IndexType
2128

2229
from redisvl.exceptions import SchemaValidationError
2330
from redisvl.redis.utils import convert_bytes

redisvl/redis/utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121
TEMPORARY,
2222
)
2323
from redis.commands.search.field import Field
24-
from redis.commands.search.index_definition import IndexDefinition
25-
from redis.commands.search.profile_information import ProfileInformation
24+
25+
# Redis 5.x compatibility (6 fixed the import path)
26+
try:
27+
from redis.commands.search.index_definition import ( # type: ignore[import-untyped]
28+
IndexDefinition,
29+
)
30+
except ModuleNotFoundError:
31+
from redis.commands.search.indexDefinition import IndexDefinition
32+
2633
from redis.commands.search.query import Query
2734
from redis.commands.search.result import Result
2835

@@ -255,11 +262,12 @@ async def async_cluster_create_index(
255262
return await default_node.execute_command(*args)
256263

257264

265+
# TODO: The return type is incorrect because 5.x doesn't have "ProfileInformation"
258266
def cluster_search(
259267
client: Search,
260268
query: Union[str, Query],
261269
query_params: Optional[Dict[str, Union[str, int, float, bytes]]] = None,
262-
) -> Union[Result, Pipeline, ProfileInformation]:
270+
) -> Union[Result, Pipeline, Any]: # type: ignore[type-arg]
263271
args, query = client._mk_query_args(query, query_params=query_params)
264272
st = time.monotonic()
265273

@@ -278,11 +286,12 @@ def cluster_search(
278286
)
279287

280288

289+
# TODO: The return type is incorrect because 5.x doesn't have "ProfileInformation"
281290
async def async_cluster_search(
282291
client: AsyncSearch,
283292
query: Union[str, Query],
284293
query_params: Optional[Dict[str, Union[str, int, float, bytes]]] = None,
285-
) -> Union[Result, Pipeline, ProfileInformation]:
294+
) -> Union[Result, Pipeline, Any]: # type: ignore[type-arg]
286295
args, query = client._mk_query_args(query, query_params=query_params)
287296
st = time.monotonic()
288297

0 commit comments

Comments
 (0)