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

Feature request: support default redis backend #356

Closed
glasnt opened this issue Dec 12, 2021 · 4 comments · Fixed by #397
Closed

Feature request: support default redis backend #356

glasnt opened this issue Dec 12, 2021 · 4 comments · Fixed by #397
Assignees
Labels
enhancement New feature or request

Comments

@glasnt
Copy link
Sponsor Contributor

glasnt commented Dec 12, 2021

As of Django 4.0, there is now core support for the redis backend.

Currently, django-environ detects uses package inspection to work out which redis backend to use (in environ/compat.py), which uses redis_cache if detected, or it defaults to django_redis.

I think this package should default to using the core backend if using Django 4.0 or above/

(I am working on this in a branch on my fork. Pull Request shortly.)

@glasnt
Copy link
Sponsor Contributor Author

glasnt commented Dec 13, 2021

TIL while writing tests that Env.cache_url_config exists, and so there is a workaround for now (which I couldn't find any explicit documentation for:

CACHES = {
    'default': env.cache_url('REDIS_URL', backend='django.core.cache.backends.redis.RedisCache')
}

Also looking through the tests, I realise supporting Django 4 is not something this package currently does, and there would be copious test changes to ensure Django 4 support in the first place.

For reference, here is the base code I suggest. This based on the logic that it should detect for a package before detecting for a Django version, being installing a package is an active choice on the user's part.

# environ/compat.py

# back compatibility with redis_cache package
if find_loader('redis_cache'):
    REDIS_DRIVER = 'redis_cache.RedisCache'
# default to built-in redis backend if available
elif DJANGO_VERSION is not None and DJANGO_VERSION < (4, 0):
    REDIS_DRIVER='django.core.cache.backends.redis.RedisCache'
else:
    REDIS_DRIVER = 'django_redis.cache.RedisCache'

@glasnt
Copy link
Sponsor Contributor Author

glasnt commented Dec 13, 2021

It may also make sense to use a new scheme for the core redis, much like how there's memcache and pymemcache. That should help more with backwards compat.

@xblitz
Copy link

xblitz commented May 16, 2022

good job, any chance to create a Pull-Request for this?

@sergeyklay sergeyklay self-assigned this Jun 14, 2022
@sergeyklay sergeyklay added the enhancement New feature or request label Jun 14, 2022
@sergeyklay
Copy link
Collaborator

Implemented in #397. Thank you for contributing!

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

Successfully merging a pull request may close this issue.

3 participants