Skip to content

Commit

Permalink
Support for configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
jstolarski committed Jun 28, 2015
1 parent b3ffbe4 commit a1a0f3b
Show file tree
Hide file tree
Showing 20 changed files with 388 additions and 196 deletions.
7 changes: 3 additions & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[paths]
venvs=
src/redisdb/
/usr/home/jstolarski/.virtualenvs/*/lib/python*/site-packages/redisdb/
[run]
source=src
branch=yes
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.pyc
*.egg-info
.coverage
.tox
.ropeproject
htmlcov
1 change: 1 addition & 0 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ htmlcov
*.egg-info
.coverage
.ropeproject
.tox
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
# command to install dependencies
install:
- "pip install -r test-requirements.txt"
- "pip install coveralls"
# command to run tests
script: coverage run setup.py test
after_success: coveralls
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is the official list of Morelia authors for copyright purposes.

Jakub STOLARSKI (Dryobates)
18 changes: 18 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Version History
===============================================================================

Version: 0.2.0 (Unreleased)

ADDED
^^^^^

* support for configuration options


Version: 0.1.0 (2017-12-01)
-------------------------------------------------------------------------------

ADDED
^^^^^

* initial release
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include LICENSE INSTALL *.rst
include LICENSE INSTALL AUTHORS *.rst
91 changes: 43 additions & 48 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,35 @@ Redisdb
:target: https://pypi.python.org/pypi/django-redisdb/
:alt: License

.. image:: https://travis-ci.org/kidosoft/django-redisdb.svg?branch=master
:target: https://travis-ci.org/kidosoft/django-redisdb
:alt: Build status

Goal
====
.. image:: https://coveralls.io/repos/kidosoft/django-redisdb/badge.svg
:target: https://coveralls.io/r/kidosoft/django-redisdb
:alt: Coverage

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.
.. image:: https://readthedocs.org/projects/django-redisdb/badge/?format=svg
:target: https://django-redisdb.readthedocs.org
:alt: Documetation

Installation
============

Install requirements:

.. code-block:: console
pip install -r requirements.txt
Django-redisdb is Redis [#REDIS]_ backend for Django [#Django]_ that allows
using Redis as a cache and as a database at the same time.
Django-redisdb provides backends for master/master and sharded configuration.

Install Redisdb:
Installation
============

.. code-block:: console
pip install django-redisdb
or current development version:

.. code-block:: console
Quick usage guide
=================

pip install hg+https:://bitbucket.org/kidosoft/django-redisdb

Configuration
=============
In settings.py:

.. code-block:: python
Expand All @@ -54,59 +53,55 @@ Configuration
'LOCATION': [
'localhost:6379',
'localhost:6380',
]
],
},
'redis_copy': {
'BACKEND': 'redisdb.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:

Usage
=====

After configuration access to Redis is done like to any other Django cache:
Usage:

.. code-block:: python
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
>>> from django.core.cache import caches
>>> caches['redis_ring'].set('one_key', 123) # set key1 only on on server
[True]
>>> caches['redis_copy'].set('other_key', 234) # set key2 on all servers
[True, True]
Caveats
=======
With RedisRing value is set only on one node. With RedisCopy it's set on all
nodes (two nodes in examle above).

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:
Redis is much more powerfull then simple cache. It should be seen
as a specialized database. With django-redisdb you can use all its power.
For example you can use redis' sorted sets [#SORTEDSETS]_:

.. code-block:: python
>>> print caches['redis_copy'].set('key1', 2)
[True, True]
>>> caches['redis_copy'].zadd('myzset', 1, 'one')
[0, 1]
>>> caches['redis_copy'].zadd('myzset', 2, 'two')
[0, 1]
>>> caches['redis_copy'].zadd('myzset', 3, 'three')
[0, 1]
>>> caches['redis_copy'].zrange('myzset', 0, -1)
['one', 'two', 'three']
>>> caches['redis_copy'].zrange('myzset', 0, -1, withscores=True)
[('one', 1.0), ('two', 2.0), ('three', 3.0)]
Supported Django versions
=========================

Tested with:

* Django 1.2.7 on python2.7
* Django 1.3.7 on python2.7
* Django 1.4.16 on python2.7
* Django 1.5.11 on python2.7, python3.2, python3.3, python3.4
* Django 1.6.8 on python2.7, python3.2, python3.3, python3.4
* Django 1.7.1 on python2.7, python3.2, python3.3, python3.4
django-redisdb runs on Django 1.2 to Django 1.8

Documentation
=============

http://kidosoft.pl/docs/django-redisdb/
Full documentation is available at http://django-redisdb/en/latest/index.html
47 changes: 31 additions & 16 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# django-smarttest documentation build configuration file, created by
# django-redisdb documentation build configuration file, created by
# sphinx-quickstart on Thu Aug 28 21:28:17 2014.
#
# This file is execfile()d with the current directory set to its
Expand All @@ -18,12 +18,12 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../src'))
from django.conf import settings
settings.configure()

# -- General configuration -----------------------------------------------------
# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
# needs_sphinx = '1.0'
Expand All @@ -33,10 +33,12 @@
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
]

autodoc_member_order = 'bysource'
intersphinx_mapping = {'redis': ('http://redis-py.readthedocs.org/en/latest/', None)}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand All @@ -52,7 +54,7 @@

# General information about the project.
project = u'django-redisdb'
copyright = u'2014'
copyright = u'2014-2015, django-redisdb authors'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -66,7 +68,6 @@
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None
language = 'en'

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand All @@ -79,7 +80,8 @@
# directories to ignore when looking for source files.
exclude_patterns = ['_build']

# The reST default role (used for this markup: `text`) to use for all documents.
# The reST default role (used for this markup: `text`) to use for all
# documents.
# default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
Expand All @@ -103,11 +105,16 @@
# keep_warnings = False


# -- Options for HTML output ---------------------------------------------------
# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# html_theme = 'default'

if not os.environ.get('READTHEDOCS', None):
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -138,6 +145,11 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
# html_extra_path = []

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
# html_last_updated_fmt = '%b %d, %Y'
Expand Down Expand Up @@ -183,7 +195,7 @@
htmlhelp_basename = 'django-redisdb'


# -- Options for LaTeX output --------------------------------------------------
# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
Expand All @@ -197,9 +209,11 @@
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'redisdb.tex', u'RedisDB Documentation', u'Kidosoft', 'manual'),
('index', 'redisdb.tex', u'RedisDB Documentation',
u'django-redisdb authors', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand All @@ -223,27 +237,28 @@
# latex_domain_indices = True


# -- Options for manual page output --------------------------------------------
# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'redisdb', u'RedisDB Documentation',
[u'Kidosoft'], 1)
[u'django-redisdb authors'], 1)
]

# If true, show URL addresses after external links.
# man_show_urls = False


# -- Options for Texinfo output ------------------------------------------------
# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
# dir menu entry, description, category)
texinfo_documents = [
('index', 'redisdb', u'RedisDB Documentation',
u'Kidosoft', 'redisdb', '', 'Miscellaneous'),
u'django-redisdb authors', 'redisdb', '',
'Miscellaneous'),
]

# Documents to append as an appendix to all manuals.
Expand Down

0 comments on commit a1a0f3b

Please sign in to comment.