File size: 1,258 Bytes
1fe6f63
 
 
 
 
 
 
 
 
7fe839d
 
 
1fe6f63
7fe839d
 
1fe6f63
 
 
 
 
 
 
 
7fe839d
 
 
1fe6f63
 
7fe839d
1fe6f63
7fe839d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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)