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

Add django4 support #219

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test

on:
- push

jobs:
build:
name: Python ${{ matrix.python-version }} / ${{ matrix.django-version }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version:
- '3.8'
- '3.9'
django-version:
- '>=3.2,<4.0'
- '>=4.2,<5.0'

env:
DJANGO_VERSION: ${{ matrix.django-version }}

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install redis
run: ./install_redis.sh

- name: Run tests
run: make test
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SHELL := /bin/bash

PACKAGE_NAME=redis_cache
DJANGO_VERSION?=>=1.11,<4.0
DJANGO_VERSION?=>=4.2,<5.0

.PHONY: install_requirements
install_requirements: requirements*.txt
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# django-redis-cache documentation build configuration file, created by
# sphinx-quickstart on Mon Jul 20 10:08:24 2015.
Expand Down
2 changes: 1 addition & 1 deletion install_redis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

: ${REDIS_VERSION:="4.0.11"}

test -d redis || git clone https://github.com/antirez/redis
test -d redis || git clone https://github.com/redis/redis
git -C redis checkout $REDIS_VERSION
make -C redis
2 changes: 1 addition & 1 deletion redis_cache/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, server, params):
"""
Connect to Redis, and set up cache backend.
"""
super(BaseRedisCache, self).__init__(params)
super().__init__(params)
self.server = server
self.servers = get_servers(server)
self.params = params or {}
Expand Down
2 changes: 1 addition & 1 deletion redis_cache/backends/multiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class ShardedRedisCache(BaseRedisCache):

def __init__(self, server, params):
super(ShardedRedisCache, self).__init__(server, params)
super().__init__(server, params)
self.sharder = HashRing()

for server in self.servers:
Expand Down
2 changes: 1 addition & 1 deletion redis_cache/backends/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, server, params):
"""
Connect to Redis, and set up cache backend.
"""
super(RedisCache, self).__init__(server, params)
super().__init__(server, params)

for server in self.servers:
client = self.create_client(server)
Expand Down
8 changes: 4 additions & 4 deletions redis_cache/compressors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
pass


class BaseCompressor(object):
class BaseCompressor:

def __init__(self, **kwargs):
super(BaseCompressor, self).__init__()
super().__init__()

def compress(self, value):
raise NotImplementedError
Expand All @@ -31,7 +31,7 @@ class ZLibCompressor(BaseCompressor):

def __init__(self, level=6):
self.level = level
super(ZLibCompressor, self).__init__()
super().__init__()

def compress(self, value):
return zlib.compress(value, self.level)
Expand All @@ -44,7 +44,7 @@ class BZip2Compressor(BaseCompressor):

def __init__(self, compresslevel=9):
self.compresslevel = compresslevel
super(BZip2Compressor, self).__init__()
super().__init__()

def compress(self, value):
return bz2.compress(value, compresslevel=self.compresslevel)
Expand Down
2 changes: 1 addition & 1 deletion redis_cache/connection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from redis.connection import UnixDomainSocketConnection, Connection, SSLConnection


class CacheConnectionPool(object):
class CacheConnectionPool:

def __init__(self):
self._clients = {}
Expand Down
10 changes: 5 additions & 5 deletions redis_cache/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from django.utils.encoding import force_bytes, force_str


class BaseSerializer(object):
class BaseSerializer:

def __init__(self, **kwargs):
super(BaseSerializer, self).__init__(**kwargs)
super().__init__(**kwargs)

def serialize(self, value):
raise NotImplementedError
Expand All @@ -30,7 +30,7 @@ def deserialize(self, value):
raise NotImplementedError


class PickleSerializer(object):
class PickleSerializer:

def __init__(self, pickle_version=-1):
self.pickle_version = pickle_version
Expand All @@ -45,7 +45,7 @@ def deserialize(self, value):
class JSONSerializer(BaseSerializer):

def __init__(self, **kwargs):
super(JSONSerializer, self).__init__(**kwargs)
super().__init__(**kwargs)

def serialize(self, value):
return force_bytes(json.dumps(value))
Expand Down Expand Up @@ -75,7 +75,7 @@ def deserialize(self, value):
class DummySerializer(BaseSerializer):

def __init__(self, **kwargs):
super(DummySerializer, self).__init__(**kwargs)
super().__init__(**kwargs)

def serialize(self, value):
return value
Expand Down
4 changes: 2 additions & 2 deletions redis_cache/sharder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def get_slot(key):
return int(digest[-DIGITS:], 16)


class Node(object):
class Node:

def __init__(self, node, i):
self._node = node
Expand All @@ -28,7 +28,7 @@ def __gt__(self, other):
)


class HashRing(object):
class HashRing:

def __init__(self, replicas=16):
self.replicas = replicas
Expand Down
2 changes: 1 addition & 1 deletion redis_cache/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def parse_connection_kwargs(server, db=None, **kwargs):
port = int(port)
except (ValueError, TypeError):
raise ImproperlyConfigured(
"{0} from {1} must be an integer".format(
"{} from {} must be an integer".format(
repr(port),
server
)
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
install_requires=['redis<4.0'],
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 3.0",
"Framework :: Django :: 3.1",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
],
)
18 changes: 6 additions & 12 deletions tests/testapp/tests/base_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from hashlib import sha1
import os
import subprocess
Expand Down Expand Up @@ -69,7 +66,7 @@ def start_redis_servers(servers, db=None, master=None):
if is_socket:
parameters.update(
port=0,
unixsocket='/tmp/redis{0}.sock'.format(i),
unixsocket=f'/tmp/redis{i}.sock',
unixsocketperm=755,
)
if master and not connection_kwargs == master_connection_kwargs:
Expand All @@ -82,7 +79,7 @@ def start_redis_servers(servers, db=None, master=None):
)

args = ['./redis/src/redis-server'] + [
"--{parameter} {value}".format(parameter=parameter, value=value)
f"--{parameter} {value}"
for parameter, value in parameters.items()
]
p = subprocess.Popen(args, stdout=devnull)
Expand All @@ -91,7 +88,7 @@ def start_redis_servers(servers, db=None, master=None):
return processes


class SetupMixin(object):
class SetupMixin:
processes = None

@classmethod
Expand Down Expand Up @@ -126,12 +123,9 @@ def setUp(self):

def tearDown(self):
# clear caches to allow @override_settings(CACHES=...) to work.
if django.VERSION < (3, 2):
caches._caches.caches = {}
else:
for alias in caches:
if hasattr(caches._connections, alias):
del caches[alias]
for alias in caches:
if hasattr(caches._connections, alias):
del caches[alias]
# Sometimes it will be necessary to skip this method because we need to
# test default initialization and that may be using a different port
# than the test redis server.
Expand Down
3 changes: 1 addition & 2 deletions tests/testapp/tests/compressor_tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
from django.test import TestCase, override_settings

from tests.testapp.tests.base_tests import BaseRedisTestCase

LOCATION = "127.0.0.1:6381"


class CompressionTestCase(object):
class CompressionTestCase:

def test_compression(self):
key = 'a'
Expand Down
7 changes: 2 additions & 5 deletions tests/testapp/tests/master_slave_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@
class MasterSlaveTestCase(SetupMixin, TestCase):

def setUp(self):
super(MasterSlaveTestCase, self).setUp()
super().setUp()
pool.reset()

def test_master_client(self):
# Reset the cache at the beginning of the test.
if django.VERSION < (3, 2):
del caches._caches.caches['default']
else:
del caches['default']
del caches['default']
cache = self.get_cache()
client = cache.master_client
self.assertEqual(
Expand Down
4 changes: 2 additions & 2 deletions tests/testapp/tests/multi_server_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def stddev(lst):
return sqrt(variance)


class MultiServerTests(object):
class MultiServerTests:

def test_distribution(self):
nodes = [node._position for node in self.cache.sharder._nodes]
Expand All @@ -32,7 +32,7 @@ def test_distribution(self):

def test_make_key_distribution(self):
ring = HashRing()
nodes = set([str(node._node) for node in self.cache.sharder._nodes])
nodes = {str(node._node) for node in self.cache.sharder._nodes}
nodes = [
('127.0.0.1', 6379, 15, '/tmp/redis0.sock'),
('127.0.0.1', 6379, 15, '/tmp/redis1.sock'),
Expand Down
3 changes: 0 additions & 3 deletions tests/testapp/tests/serializers_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import TestCase, override_settings

from tests.testapp.tests.base_tests import SetupMixin
Expand Down
1 change: 0 additions & 1 deletion tests/testapp/tests/socket_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# # -*- coding: utf-8 -*-
from collections import Counter
from tests.testapp.tests.base_tests import BaseRedisTestCase
from tests.testapp.tests.multi_server_tests import MultiServerTests
Expand Down
1 change: 0 additions & 1 deletion tests/testapp/tests/socket_timeout_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.test import TestCase, override_settings

from redis.exceptions import ConnectionError
Expand Down
1 change: 0 additions & 1 deletion tests/testapp/tests/tcp_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from tests.testapp.tests.base_tests import BaseRedisTestCase
from tests.testapp.tests.multi_server_tests import MultiServerTests
from django.test import TestCase, override_settings
Expand Down