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

Redis backend update #4376

Merged
merged 4 commits into from
Feb 13, 2024
Merged

Redis backend update #4376

merged 4 commits into from
Feb 13, 2024

Conversation

axelstudios
Copy link
Member

@axelstudios axelstudios commented Nov 1, 2023

Any background context you want to provide?

The dependency we were using to leverage Redis as the Django/Celery cache (django-redis-cache) effectively hasn't been updated since 2020, and requires redis-py < v4.0. Redis-py introduced cluster-mode in v4.1.0.

What's this PR do?

Drops the django-redis-cache dependency in favor of django-redis, which is compatible with current versions of redis-py. This PR also adds hiredis for performance.

Once we migrate to Django v4 we can use Django's built-in Redis support going forward.

How should this be manually tested?

  1. pip install -r requirements/base.txt
  2. Update your local config (usually local_untracked.py), see the migration steps below to understand what to change
  3. Test that SEED and Celery work as expected

What are the relevant tickets?

#4375

BREAKING CHANGE

This updated dependency requires users and deployments to modify their CACHES config. Django v4 uses the same syntax, so this is a necessary step regardless.

Migration Steps

  1. Update your dependencies with pip install -r requirements/base.txt
  2. Update the CACHES BACKEND property to django_redis.cache.RedisCache
  3. Update the CACHES LOCATION property to match the redis-py native URL notation for connection strings, including the redis protocol and database number. e.g. redis://localhost:6379/1
    1. Since the CELERY_BROKER_URL setting must also be in the same format, it may be helpful to configure that setting first and then reference it in the caches LOCATION parameter.

Example migration

In your Django settings file, replace existing code that looks like this:

CACHES = {
    'default': {
        'BACKEND': 'redis_cache.cache.RedisCache',
        'LOCATION': 'localhost:6379',
        'OPTIONS': {'DB': 1},
        'TIMEOUT': 300
    }
}

CELERY_BROKER_URL = 'redis://%s/%s' % (
    CACHES['default']['LOCATION'], CACHES['default']['OPTIONS']['DB']
)

with this:

CELERY_BROKER_URL = 'redis://localhost:6379/1'

CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': CELERY_BROKER_URL,
    }
}

For advanced connections, the connection string can also specify SSL, username, and password, e.g. rediss://username:password@localhost:6379/1

@axelstudios axelstudios added the Feature Add this label to new features. This will be reflected in the change log when generated. label Nov 1, 2023
@kflemin
Copy link
Contributor

kflemin commented Nov 1, 2023

@nllong what do you think?

Copy link
Member

@nllong nllong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Let's bring this up on our next call that users will need to update their local untrack files before we merge down.

@axelstudios
Copy link
Member Author

axelstudios commented Jan 11, 2024

  • Provide documentation on how to migrate configs
  • Send message to SEEDdev groups.io so users know to update their local configs

@kflemin
Copy link
Contributor

kflemin commented Jan 31, 2024

@dhaley will test this out around Feb12th to make sure it works on stratus before merging.

@axelstudios axelstudios merged commit a5a2a9d into develop Feb 13, 2024
8 checks passed
@axelstudios axelstudios deleted the task/update-redis-py branch February 13, 2024 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Add this label to new features. This will be reflected in the change log when generated.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants