Fix redis ssl issues 3
This commit is contained in:
@@ -134,22 +134,70 @@ class RedisConnectionManager:
|
||||
self._redis_url = redis_url
|
||||
|
||||
# Create connection pool with SSL handling for self-signed certificates
|
||||
connection_kwargs = {
|
||||
'db': db,
|
||||
'max_connections': max_connections,
|
||||
'decode_responses': decode_responses,
|
||||
'retry_on_timeout': retry_on_timeout,
|
||||
'socket_keepalive': socket_keepalive,
|
||||
'health_check_interval': health_check_interval
|
||||
}
|
||||
|
||||
# Add SSL kwargs for self-signed certificates (using shared helper)
|
||||
connection_kwargs.update(get_ssl_kwargs_for_url(redis_url))
|
||||
|
||||
self._pool = redis.ConnectionPool.from_url(
|
||||
redis_url,
|
||||
**connection_kwargs
|
||||
)
|
||||
# For Redis 6.4.0+, we need to handle SSL parameters correctly
|
||||
if redis_url.startswith("rediss://"):
|
||||
# Extract connection parameters from URL
|
||||
from urllib.parse import urlparse
|
||||
|
||||
parsed_url = urlparse(redis_url)
|
||||
|
||||
# Build connection parameters for ConnectionPool
|
||||
connection_params = {
|
||||
'db': db,
|
||||
'max_connections': max_connections,
|
||||
'retry_on_timeout': retry_on_timeout,
|
||||
'socket_keepalive': socket_keepalive,
|
||||
'health_check_interval': health_check_interval
|
||||
}
|
||||
|
||||
# Add password if present
|
||||
if parsed_url.password:
|
||||
connection_params['password'] = parsed_url.password
|
||||
|
||||
# Create connection pool (without SSL parameters - they go to the client)
|
||||
self._pool = redis.ConnectionPool(
|
||||
host=parsed_url.hostname,
|
||||
port=parsed_url.port or 6379,
|
||||
**connection_params
|
||||
)
|
||||
|
||||
# Get SSL configuration for self-signed certificates
|
||||
ssl_kwargs = get_ssl_kwargs_for_url(redis_url)
|
||||
|
||||
# Create Redis client with SSL parameters
|
||||
client_params = {
|
||||
'connection_pool': self._pool,
|
||||
'decode_responses': decode_responses
|
||||
}
|
||||
|
||||
if ssl_kwargs:
|
||||
client_params['ssl'] = True
|
||||
client_params['ssl_cert_reqs'] = ssl_kwargs.get('ssl_cert_reqs', ssl.CERT_NONE)
|
||||
client_params['ssl_ca_certs'] = ssl_kwargs.get('ssl_ca_certs')
|
||||
client_params['ssl_certfile'] = ssl_kwargs.get('ssl_certfile')
|
||||
client_params['ssl_keyfile'] = ssl_kwargs.get('ssl_keyfile')
|
||||
|
||||
self._client = redis.Redis(**client_params)
|
||||
else:
|
||||
# For non-TLS connections, use the original approach
|
||||
connection_kwargs = {
|
||||
'db': db,
|
||||
'max_connections': max_connections,
|
||||
'decode_responses': decode_responses,
|
||||
'retry_on_timeout': retry_on_timeout,
|
||||
'socket_keepalive': socket_keepalive,
|
||||
'health_check_interval': health_check_interval
|
||||
}
|
||||
|
||||
# Add SSL kwargs for self-signed certificates (using shared helper)
|
||||
connection_kwargs.update(get_ssl_kwargs_for_url(redis_url))
|
||||
|
||||
self._pool = redis.ConnectionPool.from_url(
|
||||
redis_url,
|
||||
**connection_kwargs
|
||||
)
|
||||
|
||||
self._client = redis.Redis(connection_pool=self._pool)
|
||||
|
||||
# Create Redis client with pool
|
||||
self._client = redis.Redis(connection_pool=self._pool)
|
||||
|
||||
Reference in New Issue
Block a user