skip to Main Content

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


  1. 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.

    import redis
    import pprint
     
    try:
      r = redis.StrictRedis(
        decode_responses=True,
        host='redis-16148.c15.us-east-1-2.ec2.cloud.redislabs.com',
        port=16148,
        password='sekret',
        ssl=True, 
        ssl_keyfile='./redislabs_user_private.key', 
        ssl_certfile='./redislabs_user.crt', 
        ssl_cert_reqs='required', 
        ssl_ca_certs='./redislabs_ca.pem',
        )
     
      info = r.info()
      pprint.pprint(info)
     
    except Exception as err:
      print("Error connecting to Redis: {}".format(err))
    

    and I got 403 forbidden, cause I don’t have an account.
    I installed redis v5.0.1

    Login or Signup to reply.
  2. 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.

    pool = redis.ConnectionPool(host=’localhost’, port=6379, db=0)
    r = redis.Redis(connection_pool=pool)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search