| import redis | |
| import os | |
| host = os.getenv("REDIS_HOST") | |
| port = int(os.getenv("REDIS_PORT", "6379")) | |
| username = os.getenv("REDIS_USERNAME") or None | |
| password = os.getenv("REDIS_PASSWORD") or None | |
| print("Connecting to Redis...") | |
| print(f"Host: {host}") | |
| print(f"Port: {port}") | |
| print(f"Username: {username}") | |
| # Test with SSL first | |
| print("\nTrying with SSL...") | |
| try: | |
| r = redis.Redis( | |
| host=host, | |
| port=port, | |
| username=username, | |
| password=password, | |
| decode_responses=True, | |
| socket_connect_timeout=5, | |
| socket_timeout=5, | |
| ssl=True, | |
| ssl_cert_reqs=None | |
| ) | |
| result = r.ping() | |
| print("✅ Ping successful with SSL:", result) | |
| except Exception as e: | |
| print("❌ Redis connection failed with SSL:", e) | |
| # Try without SSL | |
| print("\nTrying without SSL...") | |
| try: | |
| r = redis.Redis( | |
| host=host, | |
| port=port, | |
| username=username, | |
| password=password, | |
| decode_responses=True, | |
| socket_connect_timeout=5, | |
| socket_timeout=5 | |
| ) | |
| result = r.ping() | |
| print("✅ Ping successful without SSL:", result) | |
| except Exception as e2: | |
| print("❌ Redis connection failed without SSL:", e2) | |