Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

A asyncio-redis backend for Django!

Project description

# django-asyncio-redis
A `asyncio-redis` backend for Django.

This project is currently in alpha. Basic functionality is working but I am testing out various ideas for loop
management and haven't fully tested all the endpoints yet. Currently, the implementation will setup a connection
on first use with whatever loop the `asyncio-redis` library pulls (`asyncio.get_event_loop()`). This is not exactly an ideal
situation but I haven't been able to figure out how to manage loops in a global state object like `django.core.cache.cache`.

### Usage
`pip install django-asyncio-redis`

The following will set your cache backend to the `AsyncRedisCache`. It will be using `HiRedis` and connection pooling.
HiRedis is the preferred backend as it is very fast.

import os

"default": {}, # Leave your default the way it was for non async django access.
"async": {
"BACKEND": "django-asyncio-redis.cache.AsyncRedisCache",
"LOCATION": os.environ.get('REDIS_LOCATION', "redis://"),
"TIMEOUT": 1200,
"PROTOCOL_CLASS": "asyncio_redis.HiRedisProtocol",

from django.core.cache import caches
from django.http import HttpResponse
acache = caches['async']
async def my_view(request):
val = await acache.get('test-key')
return HttpResponse(val)

### All fields:
* Required.
* Specified as `redis://host:port` with optional `?db=x` to specify the database.
* Optional. Default: 0.
* Enables connection pooling.
* Optional. Default `True`.
* `LOOP`
* Optional. Default `None`.
* The IO loop to run everything on.
* Optional. Default 300.
* Specify the default cache expire time. Used in `set` type operations.
* Optional.
* Optional. Default `asyncio_redis.RedisProtocol`.
* Determines which protocol class to use.
* Choices:
* `asyncio_redis.RedisProtocol`
* `asyncio_redis.HiRedisProtocol`

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_asyncio_redis-0.1.1-py3-none-any.whl (5.7 kB) Copy SHA256 hash SHA256 Wheel py3
django-asyncio-redis-0.1.1.tar.gz (3.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page