dify/api/extensions/ext_redis.py

24 lines
723 B
Python
Raw Normal View History

2023-05-15 08:51:32 +08:00
import redis
from redis.connection import Connection, SSLConnection
2023-05-15 08:51:32 +08:00
redis_client = redis.Redis()
def init_app(app):
2023-05-17 15:40:21 +08:00
connection_class = Connection
if app.config.get('REDIS_USE_SSL'):
2023-05-17 15:40:21 +08:00
connection_class = SSLConnection
2023-05-15 08:51:32 +08:00
redis_client.connection_pool = redis.ConnectionPool(**{
'host': app.config.get('REDIS_HOST'),
'port': app.config.get('REDIS_PORT'),
'username': app.config.get('REDIS_USERNAME'),
'password': app.config.get('REDIS_PASSWORD'),
'db': app.config.get('REDIS_DB'),
2023-05-15 08:51:32 +08:00
'encoding': 'utf-8',
'encoding_errors': 'strict',
'decode_responses': False
2023-05-17 15:40:21 +08:00
}, connection_class=connection_class)
2023-05-15 08:51:32 +08:00
app.extensions['redis'] = redis_client