From a cloud run service, I successfully create a connection to google cloud Redis with:
redis_webhooks = redis.StrictRedis(
host=redis_webhooks_host,
port=redis_webhooks_port,
password=redis_webhooks_authstring,
ssl=True,
db=1,
ssl_cert_reqs="required",
ssl_ca_certs=f"/tmp/{redis_webhooks_server_ca_pem_name}",
)
I am now trying to instantiate a connection pool, for better performance, I am trying to follow docs and the official google guide and Redis guide, however none of the references how to do this with authentication
I landed on this but it doesnt work, there are unexpected keywords "ssl", then "ssl_cert_reqs" and so on.
pool = redis.ConnectionPool(
host=redis_webhooks_host,
port=redis_webhooks_port,
password=redis_webhooks_authstring,
ssl=True,
db=1,
ssl_cert_reqs="required",
ssl_ca_certs=f"/tmp/{redis_webhooks_server_ca_pem_name}",
)
redis_webhooks_client = redis.StrictRedis(connection_pool=pool)
I also tried splitting connection and authentication like:
pool = redis.ConnectionPool(
host=redis_webhooks_host,
port=redis_webhooks_port,
password=redis_webhooks_authstring,
db=1,
max_connections=100,
socket_timeout=5,
retry_on_timeout=True
)
redis_webhooks_client = redis.StrictRedis(
connection_pool=pool,
ssl=True,
ssl_cert_reqs="required",
ssl_ca_certs=f"/tmp/{redis_webhooks_server_ca_pem_name}"
)
But here i get connection reset by the peer.
Any help would be greatly appreciated, Google only provides simple examples.
Thanks!
2
Answers
From https://redis.com/blog/enabling-secure-connections-redis-enterprise-cloud-python/
I tried their example and did not get the error you mentioned.
They have more ssl settings than you.
and I got 403 forbidden, cause I don’t have an account.
I installed redis v5.0.1
Behind the scenes, redis-py uses a connection pool to manage connections to a Redis server. By default, each Redis instance you create will in turn create its own connection pool. You can override this behavior and use an existing connection pool by passing an already created connection pool instance to the connection_pool argument of the Redis class. You may choose to do this in order to implement client side sharding or have finer grain control of how connections are managed.