Skip to content

Commit 52d38f4

Browse files
authored
perf: optimize CLIENT SETINFO calls in SearchIndex.from_existing() (#358) (#395)
Reduces duplicate CLIENT SETINFO calls when creating an index from an existing Redis index by tracking client validation state. When a client is validated in from_existing(), the _client_validated flag is set to prevent redundant validation in the property getter. Addresses part of #358 by minimizing Redis command overhead during index initialization.
1 parent 80159b0 commit 52d38f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

redisvl/index/index.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def __init__(
406406
self._connection_kwargs = connection_kwargs or {}
407407
self._lock = threading.Lock()
408408

409-
self._validated_client = False
409+
self._validated_client = kwargs.pop("_client_validated", False)
410410
self._owns_redis_client = redis_client is None
411411
if self._owns_redis_client:
412412
weakref.finalize(self, self.disconnect)
@@ -449,6 +449,8 @@ def from_existing(
449449
elif redis_client:
450450
# Validate client type and set lib name
451451
RedisConnectionFactory.validate_sync_redis(redis_client)
452+
# Mark that client was already validated to avoid duplicate calls
453+
kwargs["_client_validated"] = True
452454

453455
if not redis_client:
454456
raise ValueError("Must provide either a redis_url or redis_client")
@@ -1163,7 +1165,7 @@ def __init__(
11631165
self._connection_kwargs = connection_kwargs or {}
11641166
self._lock = asyncio.Lock()
11651167

1166-
self._validated_client = False
1168+
self._validated_client = kwargs.pop("_client_validated", False)
11671169
self._owns_redis_client = redis_client is None
11681170
if self._owns_redis_client:
11691171
weakref.finalize(self, sync_wrapper(self.disconnect))
@@ -1199,6 +1201,8 @@ async def from_existing(
11991201
elif redis_client:
12001202
# Validate client type and set lib name
12011203
await RedisConnectionFactory.validate_async_redis(redis_client)
1204+
# Mark that client was already validated to avoid duplicate calls
1205+
kwargs["_client_validated"] = True
12021206

12031207
if redis_client is None:
12041208
raise ValueError(

0 commit comments

Comments
 (0)