From 00b8dd7af3209a182b97fc4934348b52c6f65a4a Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 14 Aug 2023 15:53:32 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(manager.py):=20remove=20un?= =?UTF-8?q?used=20import=20statement=20for=20redis=20module=20=F0=9F=94=A7?= =?UTF-8?q?=20chore(manager.py):=20add=20try-except=20block=20to=20handle?= =?UTF-8?q?=20ImportError=20and=20provide=20clear=20error=20message=20when?= =?UTF-8?q?=20redis-py=20package=20is=20not=20installed=20=F0=9F=94=A7=20c?= =?UTF-8?q?hore(manager.py):=20add=20import=20statement=20for=20redis=20mo?= =?UTF-8?q?dule=20in=20the=20is=5Fconnected=20method=20to=20avoid=20NameEr?= =?UTF-8?q?ror?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/services/cache/manager.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/services/cache/manager.py b/src/backend/langflow/services/cache/manager.py index 89ef7ebcf..ec9909c75 100644 --- a/src/backend/langflow/services/cache/manager.py +++ b/src/backend/langflow/services/cache/manager.py @@ -5,7 +5,6 @@ from collections import OrderedDict from langflow.services.cache.base import BaseCacheManager import pickle -import redis class InMemoryCache(BaseCacheManager): @@ -204,6 +203,13 @@ class RedisCache(BaseCacheManager): db (int, optional): Redis DB. expiration_time (int, optional): Time in seconds after which a cached item expires. Default is 1 hour. """ + try: + import redis + except ImportError as exc: + raise ImportError( + "RedisCache requires the redis-py package. Please install Langflow with the deploy extra: pip install langflow[deploy]" + ) from exc + self._client = redis.StrictRedis(host=host, port=port, db=db) self.expiration_time = expiration_time @@ -212,6 +218,8 @@ class RedisCache(BaseCacheManager): """ Check if the Redis client is connected. """ + import redis + try: self._client.ping() return True