Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does django-redis support retry on TimeOut Error while reading data? #667

Open
prasad5141 opened this issue May 19, 2023 · 14 comments
Open
Labels

Comments

@prasad5141
Copy link

I am using django-redis package version (4.12.1),

I am getting a TimeOut Exception(Intermittent issue) while reading data from the redis cache, I would like to Retry for some N number of time to fetch the data

I tried using these settings but retry is not happening "REDIS_CLIENT_KWARGS": {"retry_on_timeout": True}

Please let me know if any other settings are available to retry while reading data from redis using django-redis package.

@barkhabol
Copy link

barkhabol commented May 25, 2023

@prasad5141 Were you able to execute the retry logic for n number of times by any chance? Thanks in advance.

@esseti
Copy link

esseti commented Jun 7, 2023

Is there any news on how to use the retry?

@WisdomPill
Copy link
Member

sorry for the late reply, retry is not supported

@prasad5141
Copy link
Author

Hi @WisdomPill ,

Thanks for your reply, Shall I implement Retry?

Plan of Implementation:

  • User will specify the number of times to retry while reading data from Redis. (it will be in settings.py)
  • Code should retry a user-specified number of times, if still not able to get the data after the specified count will throw an error max retry exceeded

Please suggest to me if you have any other plan for retry, and I will try to implement it.

@WisdomPill
Copy link
Member

okay, but by default the number of retries should be zero to not change the default behaviour

@esseti
Copy link

esseti commented Jun 13, 2023

It could be a set of settings within the redis configuration.

one starting point could be to "copy" what redis-py does: https://redis-py.readthedocs.io/en/stable/retry.html

so the setting could look like:

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "RETRY": 3
            "RETRY_ON_ERROR":[...]
        }
    }
}

Still. not sure what could be supported. A retry for starting will be lovely.

@esseti
Copy link

esseti commented Aug 7, 2023

any update? @prasad5141

@amingilani
Copy link

@esseti Mind if I take this over? I have some void time coming up and would like to contribute to this package :)

@amingilani
Copy link

I'd love some clarifications:

Redis client supports 3 parameters to configure the retry behaviour:

retry: Retry instance with a Backoff strategy and the max number of retries

retry_on_error: list of Exceptions to retry on

retry_on_timeout: if True, retry on TimeoutError only

Does this signature sound fine? I can create a Retry class along with a few Backoff classes?

@esseti
Copy link

esseti commented Jan 19, 2024

I just saw this: where you able to implement it ?

@amingilani
Copy link

@esseti I haven't implemented it, I'm still waiting on clarification for how the interface should look like. Let me know when you can please.

@esseti
Copy link

esseti commented Jan 22, 2024

Not sure what i can/cannot confirm, but just mimic the parameters of the client should work. that is:

@WisdomPill
Copy link
Member

WisdomPill commented Jan 23, 2024

it is something that has to be setup at the connection factory level, following the documentation of redis-py it seems to me that it can be done by adding the right parameters here.

So I changed my mind, maybe it is supported, but I didn't try it yet, I think it can be already done using some configuration like the following

from redis.backoff import ExponentialBackoff
from redis.retry import Retry

retry = Retry(ExponentialBackoff(), 3)
retry_on_error=[BusyLoadingError, ConnectionError, TimeoutError]
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "REDIS_CLIENT_KWARGS": {
               "retry": retry,
               "retry_on_error": retry_on_error
            }
        }
    }
}

or for timeouts only

from redis.backoff import ExponentialBackoff
from redis.retry import Retry

retry = Retry(ExponentialBackoff(), 3)
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "REDIS_CLIENT_KWARGS": {
               "retry": retry,
               "retry_on_timeout": True
            }
        }
    }
}

to make it easier and cleaner we could override REDIS_CLIENT_KWARGS based on OPTIONS like @esseti suggested.

to start @amingilani I would try to write some tests mimicking the redis-py ones

@akshetpandey
Copy link

akshetpandey commented Mar 27, 2024

This already works, but the documentation is wrong. You have to use CONNECTION_POOL_KWARGS instead of REDIS_CLIENT_KWARGS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants