zigi
zigi

Reputation: 41

How to handle ConnectionError error with redis-py connection while Redis pod (on kubernetes) is restarting?

I have a problem with redis-py connection into redis on kubernetes. Few times a day redis pod restarts/moves on new one pod, but my python processes catches ConnectionError error:

enter image description here

I know, that it should bubble that exception - server is down for some time. We know that new pod will available in 5 minutes so I`m trying to set connection timeout, retries on redis-py client.

from redis.retry import Retry
from redis.backoff import ConstantBackoff
from redis.exceptions import TimeoutError, ConnectionError, NoPermissionError
import redis
import os


def get_redis_connection():
    redis_pool = redis.ConnectionPool(
        host="XXXX",
        port=1234,
        retry=Retry(ConstantBackoff(10), 30),
        retry_on_error=[
            ConnectionError, TimeoutError, NoPermissionError, ConnectionRefusedError, PermissionError
        ],
        socket_timeout=300,
        socket_connect_timeout=300,
        health_check_interval=300,
    )
    return redis.Redis(connection_pool=redis_pool)

how i should handle a redis-py connection while kubernetes pod with Redis is restarting/moving?

I'm using this connection for python-rq.

Thank you in advance. ;)

Upvotes: 2

Views: 1272

Answers (0)

Related Questions