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

Update to support Redis-py 3.x #162

Merged
merged 9 commits into from
Feb 19, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ MANIFEST
.venv
redis/
*/_build/
build/*
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: python
python:
- 2.7
- 3.4
- 3.5
- 3.6
env:
Expand All @@ -14,8 +13,6 @@ matrix:
env: DJANGO_VERSION='>=2.0,<2.1'
- python: 2.7
env: DJANGO_VERSION='>=2.1,<2.2'
- python: 3.4
env: DJANGO_VERSION='>=2.1,<2.2'
# command to run tests
install: ./install_redis.sh
script: make test DJANGO_VERSION=$DJANGO_VERSION
Expand Down
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/.
Changelog
=========

2.0.0
-----

* Adds support for redis-py >= 3.0.
* Drops support for Redis 2.6.
* Drops support for Python 3.4.
* Removes custom ``expire`` method in lieu of Django's ``touch``.
* Removes ``CacheKey`` in favor of string literals.


1.8.0
-----

Expand Down
30 changes: 21 additions & 9 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ Standard Django Cache API
:param version: Version of key
:type version: Integer or None

.. function:: touch(self, key, timeout):

Updates the timeout on a key.

:param key: Location of the value
:rtype: bool



Cache Methods Provided by django-redis-cache
Expand Down Expand Up @@ -124,14 +131,22 @@ Cache Methods Provided by django-redis-cache
:param version: Version of the keys


.. function:: get_or_set(self, key, func[, timeout=None]):
.. function:: get_or_set(self, key, func[, timeout=None, lock_timeout=None, stale_cache_timeout=None]):

Get a value from the cache or call ``func`` to set it and return it.

Retrieves a key value from the cache and sets the value if it does not exist.
This implementation is slightly more advanced that Django's. It provides thundering herd
protection, which prevents multiple threads/processes from calling the value-generating
function at the same time.

:param key: Location of the value
:param func: Callable used to set the value if key does not exist.
:param timeout: Number of seconds to hold value in cache.
:param timeout: Time in seconds that value at key is considered fresh.
:type timeout: Number of seconds or None
:param lock_timeout: Time in seconds that the lock will stay active and prevent other threads from acquiring the lock.
:type lock_timeout: Number of seconds or None
:param stale_cache_timeout: Time in seconds that the stale cache will remain after the key has expired. If ``None`` is specified, the stale value will remain indefinitely.
:type stale_cache_timeout: Number of seconds or None


.. function:: reinsert_keys(self):
Expand All @@ -147,12 +162,9 @@ Cache Methods Provided by django-redis-cache
:param key: Location of the value
:rtype: bool

.. function:: lock(self, key, timeout=None, sleep=0.1, blocking_timeout=None, thread_local=True)

.. function:: expire(self, key, timeout):

Set the expire time on a key

:param key: Location of the value
:rtype: bool
See docs for `redis-py`_.


.. _redis-py: https://redis-py.readthedocs.io/en/latest/_modules/redis/client.html#Redis.lock
10 changes: 5 additions & 5 deletions docs/intro_quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Intro and Quick Start
Intro
=====

`django-redis-cache`_ is a cache backend for the `Django`_ webframework. It
`django-redis-cache`_ is a cache backend for the `Django`_ web framework. It
uses the `redis`_ server, which is a in-memory key-value data structure server.
Similar to the great `Memcached`_ in performance, it has several features that
makes it more appealing.
Expand All @@ -24,7 +24,7 @@ makes it more appealing.
* Many more.

Many of these features are irrelevant to caching, but can be used by other
areas of a web stack and therefore offer a compelling case to simplify your
areas of a web stack and therefore offers a compelling case to simplify your
infrastructure.


Expand All @@ -35,9 +35,9 @@ Quick Start

**Recommended:**

* `redis`_ >= 2.4
* `redis`_ >= 2.8

* `redis-py`_ >= 2.10.3
* `redis-py`_ >= 3.0.0

* `python`_ >= 2.7

Expand All @@ -59,7 +59,7 @@ of redis. Start the server by running ``./src/redis-server``
}

**Warning: By default, django-redis-cache set keys in the database 1 of Redis. By default, a session with redis-cli start on database 0. Switch to database 1 with** ``SELECT 1``.

.. _Django: https://www.djangoproject.com/
.. _django-redis-cache: http://github.com/sebleier/django-redis-cache
.. _redis-py: http://github.com/andymccurdy/redis-py/
Expand Down
Loading