@@ -167,6 +167,13 @@ def get_by_key(self, key: str) -> Optional[Dict[str, Any]]:
167
167
168
168
embedding_data = cache.get_by_key("embedcache:1234567890abcdef")
169
169
"""
170
+ if self ._owns_redis_client is False and self ._redis_client is None :
171
+ logger .warning (
172
+ "You are using redis_client but you had initialised the EmbeddingCache with an async_redis_client only. "
173
+ "If you intended to use async_redis_client, please use async aget(text, model_name) method of EmbeddingCache instead "
174
+ "of get(text, model_name)."
175
+ )
176
+
170
177
client = self ._get_redis_client ()
171
178
172
179
# Get all fields
@@ -202,6 +209,13 @@ def mget_by_keys(self, keys: List[str]) -> List[Optional[Dict[str, Any]]]:
202
209
if not keys :
203
210
return []
204
211
212
+ if self ._owns_redis_client is False and self ._redis_client is None :
213
+ logger .warning (
214
+ "You are using redis_client but you had initialised the EmbeddingCache with an async_redis_client only. "
215
+ "If you intended to use async_redis_client, please use async amget(texts, model_name) method of EmbeddingCache instead "
216
+ "of mget(texts, model_name)."
217
+ )
218
+
205
219
client = self ._get_redis_client ()
206
220
207
221
with client .pipeline (transaction = False ) as pipeline :
@@ -283,6 +297,13 @@ def set(
283
297
text , model_name , embedding , metadata
284
298
)
285
299
300
+ if self ._owns_redis_client is False and self ._redis_client is None :
301
+ logger .warning (
302
+ "You are using redis_client but you had initialised the EmbeddingCache with an async_redis_client only. "
303
+ "If you intended to use async_redis_client, please use async aset(text, model_name, embedding, metadata=None, ttl=None) "
304
+ "method of EmbeddingCache instead of set(text, model_name, embedding, metadata=None, ttl=None)."
305
+ )
306
+
286
307
# Store in Redis
287
308
client = self ._get_redis_client ()
288
309
client .hset (name = key , mapping = cache_entry ) # type: ignore
@@ -333,6 +354,13 @@ def mset(
333
354
if not items :
334
355
return []
335
356
357
+ if self ._owns_redis_client is False and self ._redis_client is None :
358
+ logger .warning (
359
+ "You are using redis_client but you had initialised the EmbeddingCache with an async_redis_client only. "
360
+ "If you intended to use async_redis_client, please use async amset(items, ttl=None) method of EmbeddingCache instead "
361
+ "of mset(items, ttl=None)."
362
+ )
363
+
336
364
client = self ._get_redis_client ()
337
365
keys = []
338
366
0 commit comments