from redis import from_url, ConnectionPool, Redis # Set up Redis connection for Flask-Limiter def setup_redis(app): try: pool = ConnectionPool.from_url(app.config['REDIS_URL']) redis_connection = Redis(connection_pool=pool) redis_connection.ping() app.logger.info("Connected to Redis") # Return the redis_connection to be used elsewhere return redis_connection except Exception as e: app.logger.error(f"Failed to connect to Redis: {str(e)}") return None