🔧 chore(manager.py): remove unused import statement for redis module
🔧 chore(manager.py): add try-except block to handle ImportError and provide clear error message when redis-py package is not installed 🔧 chore(manager.py): add import statement for redis module in the is_connected method to avoid NameError
This commit is contained in:
parent
e8d3a5df6d
commit
00b8dd7af3
1 changed files with 9 additions and 1 deletions
10
src/backend/langflow/services/cache/manager.py
vendored
10
src/backend/langflow/services/cache/manager.py
vendored
|
|
@ -5,7 +5,6 @@ from collections import OrderedDict
|
||||||
from langflow.services.cache.base import BaseCacheManager
|
from langflow.services.cache.base import BaseCacheManager
|
||||||
|
|
||||||
import pickle
|
import pickle
|
||||||
import redis
|
|
||||||
|
|
||||||
|
|
||||||
class InMemoryCache(BaseCacheManager):
|
class InMemoryCache(BaseCacheManager):
|
||||||
|
|
@ -204,6 +203,13 @@ class RedisCache(BaseCacheManager):
|
||||||
db (int, optional): Redis DB.
|
db (int, optional): Redis DB.
|
||||||
expiration_time (int, optional): Time in seconds after which a cached item expires. Default is 1 hour.
|
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._client = redis.StrictRedis(host=host, port=port, db=db)
|
||||||
self.expiration_time = expiration_time
|
self.expiration_time = expiration_time
|
||||||
|
|
||||||
|
|
@ -212,6 +218,8 @@ class RedisCache(BaseCacheManager):
|
||||||
"""
|
"""
|
||||||
Check if the Redis client is connected.
|
Check if the Redis client is connected.
|
||||||
"""
|
"""
|
||||||
|
import redis
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._client.ping()
|
self._client.ping()
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue