Skip to content

Commit 4945d70

Browse files
refactor get modules
1 parent 6290276 commit 4945d70

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

redisvl/index/index.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from redisvl.redis.connection import (
2828
RedisConnectionFactory,
2929
convert_index_info_to_schema,
30-
unpack_redis_modules,
3130
validate_modules,
3231
)
3332
from redisvl.redis.utils import convert_bytes
@@ -340,9 +339,7 @@ def from_existing(
340339
)
341340

342341
# Validate modules
343-
installed_modules = unpack_redis_modules(
344-
convert_bytes(redis_client.module_list())
345-
)
342+
installed_modules = RedisConnectionFactory._get_modules(redis_client)
346343
validate_modules(installed_modules, [{"name": "search", "ver": 20810}])
347344

348345
# Fetch index info and convert to schema
@@ -757,9 +754,7 @@ async def from_existing(
757754
)
758755

759756
# Validate modules
760-
installed_modules = unpack_redis_modules(
761-
convert_bytes(await redis_client.module_list())
762-
)
757+
installed_modules = await RedisConnectionFactory._get_modules_async(redis_client)
763758
validate_modules(installed_modules, [{"name": "search", "ver": 20810}])
764759

765760
# Fetch index info and convert to schema

redisvl/redis/connection.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ def validate_redis(
233233
client, lib_name, required_modules
234234
)
235235

236+
@staticmethod
237+
def _get_modules(client: Redis) -> Dict[str, Any]:
238+
return unpack_redis_modules(
239+
convert_bytes(client.module_list())
240+
)
241+
242+
@staticmethod
243+
async def _get_modules_async(client: AsyncRedis) -> Dict[str, Any]:
244+
return unpack_redis_modules(
245+
convert_bytes(await client.module_list())
246+
)
247+
236248
@staticmethod
237249
def _validate_sync_redis(
238250
client: Redis,
@@ -249,7 +261,7 @@ def _validate_sync_redis(
249261
client.echo(_lib_name)
250262

251263
# Get list of modules
252-
installed_modules = unpack_redis_modules(convert_bytes(client.module_list()))
264+
installed_modules = RedisConnectionFactory._get_modules(client)
253265

254266
# Validate available modules
255267
validate_modules(installed_modules, required_modules)
@@ -270,9 +282,7 @@ async def _validate_async_redis(
270282
await client.echo(_lib_name)
271283

272284
# Get list of modules
273-
installed_modules = unpack_redis_modules(
274-
convert_bytes(await client.module_list())
275-
)
285+
installed_modules = await RedisConnectionFactory._get_modules_async(client)
276286

277287
# Validate available modules
278288
validate_modules(installed_modules, required_modules)

tests/integration/test_search_index.py

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def test_search_index_from_existing(client, index):
6868

6969

7070
def test_search_index_from_existing_complex(client):
71+
if not compare_versions(redis_version, "7.2.0"):
72+
pytest.skip("Not using a late enough version of Redis")
7173
schema = {
7274
"index": {
7375
"name": "test",

0 commit comments

Comments
 (0)