from flask import Blueprint, jsonify
import redis, traceback
from app.core.config import settings

debug = Blueprint("debug", __name__)

redis_client = redis.Redis(
    host=settings.REDIS_HOST,
    port=settings.REDIS_PORT,
    password=settings.REDIS_PASSWORD or None,
    db=0,
    decode_responses=True,
)

@debug.route("/redis_debug")
def redis_debug():
    try:
        ok = redis_client.ping()
        return jsonify({"ping": ok}), 200
    except Exception as e:
        # print full traceback
        import traceback; traceback.print_exc()
        # also return the message so you can inspect via a tool like curl
        return jsonify({"error": str(e)}), 500

