Django redis backend
Project description
Goal
Provide Redis backends for Django that faciliates using multiple Redis servers in the same time like if they were in master/master or sharded configuration.
Installation
pip install django-kidoredis
or current development version:
pip install hg+https:://bitbucket.org/kidosoft/django-kidoredis
Configuration
CACHES = {
'redis_ring': {
'BACKEND': 'kidoredis.backends.RedisRing', # sharding backend
'DB': 0,
'LOCATION': [
'localhost:6379',
'localhost:6380',
]
},
'redis_copy': {
'BACKEND': 'kidoredis.backends.RedisCopy', # copying backend
'DB': 0,
'LOCATION': [
'localhost:6379',
'localhost:6380',
]
}
}
Redis is configured as cache backend although it should be treat as specialized database. There are two backends:
How to use
After configuration access to Redis is done like to any other Django cache:
from django.core.cache import caches
caches['redis_ring'].set('key1', 1) # set key1 only on on server
caches['redis_copy'].set('key2', 2) # set key2 on all servers
result_list = caches['redis_copy'].zrange('key3', 1, 10) # redis only command
Caveats
RedisCopy can save data to many nodes. Each of this nodes can return different result on save. For that reason commands that save data to nodes returns list of results from each node. E.g. with two nodes set for redis_copy:
>>> print caches['redis_copy'].set('key1', 2)
[True, True]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-kidoredis-1.0.tar.gz
(54.8 kB
view hashes)
Built Distribution
Close
Hashes for django_kidoredis-1.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9f1b7e3f9e7359c4c72d45734f720a209e7d2240f74b128c18f6ebac676cb07 |
|
MD5 | 44332ae9f65553f0052e9b92dbbfe9d7 |
|
BLAKE2b-256 | 6cc58d78af767481c111e8d9ef6e0e2b4b9597d66b4c1e476eb69810c5c2001d |