ext_redis.py 783 B

123456789101112131415161718192021222324252627
  1. import redis
  2. from redis.connection import Connection, SSLConnection
  3. redis_client = redis.Redis()
  4. def init_app(app):
  5. connection_class = Connection
  6. if app.config.get("REDIS_USE_SSL"):
  7. connection_class = SSLConnection
  8. redis_client.connection_pool = redis.ConnectionPool(
  9. **{
  10. "host": app.config.get("REDIS_HOST"),
  11. "port": app.config.get("REDIS_PORT"),
  12. "username": app.config.get("REDIS_USERNAME"),
  13. "password": app.config.get("REDIS_PASSWORD"),
  14. "db": app.config.get("REDIS_DB"),
  15. "encoding": "utf-8",
  16. "encoding_errors": "strict",
  17. "decode_responses": False,
  18. },
  19. connection_class=connection_class,
  20. )
  21. app.extensions["redis"] = redis_client