3939# Check Redis connection (non-blocking)
4040echo " [3/5] Checking Redis connection..." >&2
4141if [ -n " $REDIS_URL " ]; then
42- # Extract host and port from Redis URL
43- REDIS_HOST=$( echo " $REDIS_URL " | sed -E ' s|redis://([^:@]+:)?([^@:]+)(:([0-9]+))?.*|\2|' )
44- REDIS_PORT=$( echo " $REDIS_URL " | sed -E ' s|.*:([0-9]+)(/[0-9]+)?$|\1|' )
42+ # Extract host and port from Redis URL properly handling passwords with special chars
43+ # Format: redis://[user[:password]@]host:port[/db]
44+ # Remove protocol
45+ REDIS_CONN=$( echo " $REDIS_URL " | sed ' s|^redis://||' )
46+
47+ # Extract host:port by removing everything before @ (if @ exists) and after / (if / exists)
48+ if echo " $REDIS_CONN " | grep -q ' @' ; then
49+ # Has authentication - get everything after @
50+ REDIS_HOST_PORT=$( echo " $REDIS_CONN " | sed ' s|.*@||' | sed ' s|/.*||' )
51+ else
52+ # No authentication - just get host:port
53+ REDIS_HOST_PORT=$( echo " $REDIS_CONN " | sed ' s|/.*||' )
54+ fi
55+
56+ # Split host and port
57+ REDIS_HOST=$( echo " $REDIS_HOST_PORT " | cut -d: -f1)
58+ REDIS_PORT=$( echo " $REDIS_HOST_PORT " | cut -d: -f2)
4559
4660 echo " → Redis: ${REDIS_HOST} :${REDIS_PORT} " >&2
4761
@@ -50,7 +64,15 @@ if [ -n "$REDIS_URL" ]; then
5064 echo " ✓ Redis is reachable" >&2
5165 else
5266 echo " ⚠ Redis connection failed - Sidekiq will not work properly" >&2
53- echo " → REDIS_URL: ${REDIS_URL} " >&2
67+ echo " → Hostname resolution issue or Redis not accessible" >&2
68+ echo " → Attempting DNS resolution for ${REDIS_HOST} ..." >&2
69+ if command -v host > /dev/null 2>&1 ; then
70+ host " $REDIS_HOST " >&2 || echo " ✗ DNS resolution failed" >&2
71+ elif command -v nslookup > /dev/null 2>&1 ; then
72+ nslookup " $REDIS_HOST " >&2 || echo " ✗ DNS resolution failed" >&2
73+ else
74+ echo " → No DNS tools available to diagnose" >&2
75+ fi
5476 fi
5577else
5678 echo " ⚠ No REDIS_URL configured, Sidekiq will run in inline mode" >&2
0 commit comments