Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,34 @@ jobs:
matrix:
include:

- python-version: "3.8"
django-version: Django==3.2

- python-version: "3.8"
django-version: Django==4.2

- python-version: "3.9"
django-version: Django==3.2

- python-version: "3.9"
django-version: Django==4.2

- python-version: "3.10"
django-version: Django==3.2

- python-version: "3.10"
django-version: Django==4.2

- python-version: "3.10"
django-version: Django==5.0

- python-version: "3.11"
django-version: Django==3.2
django-version: Django==5.2

- python-version: "3.11"
django-version: Django==4.2

- python-version: "3.11"
django-version: Django==5.0
django-version: Django==5.2

- python-version: "3.12"
django-version: Django==4.2

- python-version: "3.12"
django-version: Django==5.0
django-version: Django==5.2

- python-version: "3.12"
django-version: Django==6.0

name: Run Python ${{ matrix.python-version }} tests
name: Run Python ${{ matrix.python-version }}, ${{ matrix.django-version }} tests
steps:
- uses: actions/checkout@v4
- name: Setup python ${{ matrix.python-version }}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

v3.4.6
------

- Drop support for Django 3.2 and 5.0
- Add support for Django 5.2 and 6.0

v3.4.5
------

Expand Down
10 changes: 3 additions & 7 deletions django_cache_url/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os
import re

from django import VERSION

try:
import urllib.parse as urlparse
except ImportError: # python 2
Expand All @@ -25,12 +23,10 @@
urlparse.uses_netloc.append('hiredis')

DEFAULT_ENV = 'CACHE_URL'
# TODO Remove as soon as Django 3.2 goes EOL
BUILTIN_DJANGO_BACKEND = 'django.core.cache.backends.redis.RedisCache'

DJANGO_REDIS_CACHE_LIB_KEY = 'redis-cache'
DJANGO_REDIS_CACHE_BACKEND = 'redis_cache.RedisCache'
DJANGO_REDIS_BACKEND = 'django_redis.cache.RedisCache' if VERSION[0] < 4 else BUILTIN_DJANGO_BACKEND
DJANGO_REDIS_BACKEND = 'django.core.cache.backends.redis.RedisCache'

BACKENDS = {
'db': 'django.core.cache.backends.db.DatabaseCache',
Expand Down Expand Up @@ -108,14 +104,14 @@ def parse(url):
config['LOCATION'] = ';'.join(url.netloc.split(','))

if url.scheme in ('redis', 'rediss', 'hiredis'):
if url.password and lib != DJANGO_REDIS_CACHE_LIB_KEY and backend != BUILTIN_DJANGO_BACKEND:
if url.password and lib != DJANGO_REDIS_CACHE_LIB_KEY and backend != DJANGO_REDIS_BACKEND:
redis_options['PASSWORD'] = url.password
# Specifying the database is optional, use db 0 if not specified.
db = path[1:] or '0'
port = url.port if url.port else 6379
scheme = 'rediss' if url.scheme == 'rediss' else 'redis'
config['LOCATION'] = f'{scheme}://{url.hostname}:{port}/{db}'
if url.password and (lib == DJANGO_REDIS_CACHE_LIB_KEY or backend == BUILTIN_DJANGO_BACKEND):
if url.password and (lib == DJANGO_REDIS_CACHE_LIB_KEY or backend == DJANGO_REDIS_BACKEND):
config['LOCATION'] = f'{scheme}://:{url.password}@{url.hostname}:{port}/{db}'

if lib == DJANGO_REDIS_CACHE_LIB_KEY:
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
classifiers=[
'Development Status :: 5 - Production/Stable',
'Framework :: Django',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.1',
'Framework :: Django :: 4.2',
'Framework :: Django :: 5.0',
'Framework :: Django :: 5.2',
'Framework :: Django :: 6.0',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
Expand Down
19 changes: 2 additions & 17 deletions tests/test_redis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import pytest

from django import VERSION as DJANGO_VERSION

import django_cache_url

#
Expand Down Expand Up @@ -31,7 +27,7 @@ def test_hiredis_socket():
# REDIS
#

def test_redis_dj4():
def test_redis():
url = 'redis://127.0.0.1:6379/0?key_prefix=site1'
config = django_cache_url.parse(url)

Expand All @@ -47,21 +43,10 @@ def test_redis_socket():
assert 'OPTIONS' not in config


@pytest.mark.skipif(DJANGO_VERSION[0] >= 4, reason="requires Django 3 or lower")
def test_redis_with_password_dj3():
def test_redis_with_password():
url = 'redis://:redispass@127.0.0.1:6379/0'
config = django_cache_url.parse(url)

assert config['BACKEND'] == django_cache_url.DJANGO_REDIS_BACKEND
assert config['LOCATION'] == 'redis://127.0.0.1:6379/0'
assert config['OPTIONS']['PASSWORD'] == 'redispass'


@pytest.mark.skipif(DJANGO_VERSION[0] < 4, reason="requires Django 4 or higher")
def test_redis_with_password_dj4():
url = 'redis://:redispass@127.0.0.1:6379/0'
config = django_cache_url.parse(url)

assert config['BACKEND'] == django_cache_url.BUILTIN_DJANGO_BACKEND
assert config['LOCATION'] == 'redis://:redispass@127.0.0.1:6379/0'
assert 'PASSWORD' not in config.get('OPTIONS', {})