django-redis-sessions-0.6.1/0000775000175000017500000000000013164406470016545 5ustar martinmartin00000000000000django-redis-sessions-0.6.1/tests/0000775000175000017500000000000013164406470017707 5ustar martinmartin00000000000000django-redis-sessions-0.6.1/tests/__init__.pyc0000664000175000017500000000044013157156760022167 0ustar martinmartin00000000000000ó À&°Yc@s$ddlmZejddƒdS(iÿÿÿÿ(tsettingstSESSION_ENGINEsredis_sessions.sessionN(t django.confRt configure(((s=/home/martin/personal/django-redis-sessions/tests/__init__.pyts django-redis-sessions-0.6.1/tests/tests.py0000664000175000017500000001241613157162070021424 0ustar martinmartin00000000000000import time from random import randint from nose.tools import eq_, assert_false from redis_sessions.session import SessionStore from redis_sessions.session import RedisServer from redis_sessions import settings ## Dev import redis import timeit redis_session = SessionStore() def test_modify_and_keys(): eq_(redis_session.modified, False) redis_session['test'] = 'test_me' eq_(redis_session.modified, True) eq_(redis_session['test'], 'test_me') def test_session_load_does_not_create_record(): session = SessionStore('someunknownkey') session.load() eq_(redis_session.exists(redis_session.session_key), False) def test_save_and_delete(): redis_session['key'] = 'value' redis_session.save() eq_(redis_session.exists(redis_session.session_key), True) redis_session.delete(redis_session.session_key) eq_(redis_session.exists(redis_session.session_key), False) def test_flush(): redis_session['key'] = 'another_value' redis_session.save() key = redis_session.session_key redis_session.flush() eq_(redis_session.exists(key), False) def test_items(): redis_session['item1'], redis_session['item2'] = 1, 2 redis_session.save() # Python 3.* eq_(set(list(redis_session.items())), set([('item2', 2), ('item1', 1)])) def test_expiry(): redis_session.set_expiry(1) # Test if the expiry age is set correctly eq_(redis_session.get_expiry_age(), 1) redis_session['key'] = 'expiring_value' redis_session.save() key = redis_session.session_key eq_(redis_session.exists(key), True) time.sleep(2) eq_(redis_session.exists(key), False) def test_save_and_load(): redis_session.set_expiry(60) redis_session.setdefault('item_test', 8) redis_session.save() session_data = redis_session.load() eq_(session_data.get('item_test'), 8) def test_with_redis_url_config(): settings.SESSION_REDIS_URL = 'redis://localhost' from redis_sessions.session import SessionStore redis_session = SessionStore() server = redis_session.server host = server.connection_pool.connection_kwargs.get('host') port = server.connection_pool.connection_kwargs.get('port') db = server.connection_pool.connection_kwargs.get('db') eq_(host, 'localhost') eq_(port, 6379) eq_(db, 0) def test_one_connection_is_used(): session = SessionStore('session_key_1') session['key1'] = 'value1' session.save() redis_server = session.server set_client_name_1 = 'client_name_' + str(randint(1, 1000)) redis_server.client_setname(set_client_name_1) client_name_1 = redis_server.client_getname() eq_(set_client_name_1, client_name_1) del session session = SessionStore('session_key_2') session['key2'] = 'value2' session.save() redis_server = session.server client_name_2 = redis_server.client_getname() eq_(client_name_1, client_name_2) def test_redis_pool_server_select(): servers = [ { 'HOST': 'localhost2', 'PORT': 6379, 'DB': 0, 'PASSWORD': None, 'UNIX_DOMAIN_SOCKET_PATH': None, 'WEIGHT': 1, }, { 'HOST': 'localhost1', 'PORT': 6379, 'DB': 0, 'PASSWORD': None, 'UNIX_DOMAIN_SOCKET_PATH': None, 'WEIGHT': 1, }, ] keys1 = [ 'm8f0os91g40fsq8eul6tejqpp6k22', 'kcffsbb5o272et1d5e6ib7gh75pd9', 'gqldpha87m8183vl9s8uqobcr2ws3', 'ukb9bg2jifrr60fstla67knjv3e32', 'k3dranjfna7fv7ijpofs6l6bj2pw1', 'an4no833idr9jddr960r8ikai5nh3', '16b9gardpcscrj5q4a4kf3c4u7tq8', 'etdefnorfbvfc165c5airu77p2pl9', 'mr778ou0sqqme21gjdiu4drtc0bv4', 'ctkgd8knu5hukdrdue6im28p90kt7' ] keys2 = [ 'jgpsbmjj6030fdr3aefg37nq47nb8', 'prsv0trk66jc100pipm6bb78c3pl2', '84ksqj2vqral7c6ped9hcnq940qq1', 'bv2uc3q48rm8ubipjmolgnhul0ou3', '6c8oph72pfsg3db37qsefn3746fg4', 'tbc0sjtl2bkp5i9n2j2jiqf4r0bg9', 'v0on9rorn71913o3rpqhvkknc1wm5', 'lmsv98ns819uo2klk3s1nusqm0mr0', '0foo2bkgvrlk3jt2tjbssrsc47tr3', '05ure0f6r5jjlsgaimsuk4n1k2sx6', ] rs = RedisServer('') for key in keys1: server_key, server = rs.get_server(key, servers) eq_(server_key, 1) for key in keys2: server_key, server = rs.get_server(key, servers) eq_(server_key, 0) def test_with_unix_url_config(): pass # Uncomment this in `redis.conf`: # # unixsocket /tmp/redis.sock # unixsocketperm 755 #settings.SESSION_REDIS_URL = 'unix:///tmp/redis.sock' #from redis_sessions.session import SessionStore # redis_session = SessionStore() # server = redis_session.server # # host = server.connection_pool.connection_kwargs.get('host') # port = server.connection_pool.connection_kwargs.get('port') # db = server.connection_pool.connection_kwargs.get('db') # # eq_(host, 'localhost') # eq_(port, 6379) # eq_(db, 0) # def test_load(): # redis_session.set_expiry(60) # redis_session['item1'], redis_session['item2'] = 1,2 # redis_session.save() # session_data = redis_session.server.get(redis_session.session_key) # expiry, data = int(session_data[:15]), session_data[15:] django-redis-sessions-0.6.1/tests/__init__.py0000664000175000017500000000014513154023300022002 0ustar martinmartin00000000000000from django.conf import settings settings.configure( SESSION_ENGINE='redis_sessions.session' ) django-redis-sessions-0.6.1/tests/tests.pyc0000664000175000017500000001211113154026237021560 0ustar martinmartin00000000000000ó À&°Yc@sêddlmZddlmZddlmZddlZddlmZmZddl m Z ddl Z ddl Z eƒZ d„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„ZdS(iÿÿÿÿ(t SessionStore(t RedisServer(tsettingsN(teq_t assert_false(trandintcCs?ttjtƒdtds&             7django-redis-sessions-0.6.1/tests/__pycache__/0000775000175000017500000000000013164406470022117 5ustar martinmartin00000000000000django-redis-sessions-0.6.1/tests/__pycache__/__init__.cpython-35.pyc0000664000175000017500000000040713154025700026274 0ustar martinmartin00000000000000 À&°Yeã@s$ddlmZejddƒdS)é)ÚsettingsZSESSION_ENGINEzredis_sessions.sessionN)Z django.confrÚ configure©rrú=/home/martin/personal/django-redis-sessions/tests/__init__.pyÚs django-redis-sessions-0.6.1/tests/__pycache__/tests.cpython-35.pyc0000664000175000017500000001110613157211527025704 0ustar martinmartin00000000000000 8ä¼Yã@s ddlZddlmZddlmZmZddlmZddlmZddl m Z ddl Z ddl Z eƒZ dd„Zd d „Zd d „Zd d„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„ZdS)éN)Úrandint)Úeq_Ú assert_false)Ú SessionStore)Ú RedisServer)ÚsettingscCs?ttjdƒdtds&             8django-redis-sessions-0.6.1/PKG-INFO0000664000175000017500000001053613164406470017647 0ustar martinmartin00000000000000Metadata-Version: 1.1 Name: django-redis-sessions Version: 0.6.1 Summary: Redis Session Backend For Django Home-page: http://github.com/martinrusev/django-redis-sessions Author: Martin Rusev Author-email: martin@amon.cx License: BSD Description: django-redis-sessions ===================== Redis database backend for your sessions |Build Status| - `Installation`_ - `Available Settings`_ - `Changelog`_ Installation ============ - Run ``pip install django-redis-sessions`` or alternatively download the tarball and run ``python setup.py install``, For Django < 1.4 run ``pip install django-redis-sessions==0.3`` - Set ``redis_sessions.session`` as your session engine, like so: .. code:: python SESSION_ENGINE = 'redis_sessions.session' Available Settings ================== .. code:: python SESSION_REDIS = { 'host': 'localhost', 'port': 6379, 'db': 0, 'password': 'password', 'prefix': 'session', 'socket_timeout': 1 } If you prefer domain socket connection, you can just add this line instead of HOST and PORT. .. code:: python SESSION_REDIS = { 'unix_domain_socket_path': '/var/run/redis/redis.sock', 'db': 0, 'password': 'password', 'prefix': 'session', 'socket_timeout': 1 } Redis Sentinel ~~~~~~~~~~~~~~ .. code:: python SESSION_REDIS_SENTINEL_LIST = [(host, port), (host, port), (host, port)] SESSION_REDIS_SENTINEL_MASTER_ALIAS = 'sentinel-master' Redis Pool (Horizontal partitioning) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Splits sessions between Redis instances based on the session key. You can configure the connection type for each Redis instance in the pool (host/port, unix socket, redis url). .. code:: python SESSION_REDIS = { 'prefix': 'session', 'socket_timeout': 1 'retry_on_timeout': False, 'pool': [{ 'host': 'localhost3', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1 }, { 'host': 'localhost2', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1 }, { 'host': 'localhost1', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1 }] } Tests ===== .. code:: bash $ pip install -r dev_requirements.txt # Make sure you have redis running on localhost:6379 $ nosetests -v `Changelog `__ ============================================================================================= .. _Installation: #installation .. _Available Settings: #available-settings .. _Changelog: #changelog .. |Build Status| image:: https://travis-ci.org/martinrusev/django-redis-sessions.svg?branch=master :target: https://travis-ci.org/martinrusev/django-redis-sessions Keywords: django,sessions, Platform: UNKNOWN Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Framework :: Django Classifier: Environment :: Web Environment django-redis-sessions-0.6.1/README.rst0000664000175000017500000000557613157703100020241 0ustar martinmartin00000000000000django-redis-sessions ===================== Redis database backend for your sessions |Build Status| - `Installation`_ - `Available Settings`_ - `Changelog`_ Installation ============ - Run ``pip install django-redis-sessions`` or alternatively download the tarball and run ``python setup.py install``, For Django < 1.4 run ``pip install django-redis-sessions==0.3`` - Set ``redis_sessions.session`` as your session engine, like so: .. code:: python SESSION_ENGINE = 'redis_sessions.session' Available Settings ================== .. code:: python SESSION_REDIS = { 'host': 'localhost', 'port': 6379, 'db': 0, 'password': 'password', 'prefix': 'session', 'socket_timeout': 1 } If you prefer domain socket connection, you can just add this line instead of HOST and PORT. .. code:: python SESSION_REDIS = { 'unix_domain_socket_path': '/var/run/redis/redis.sock', 'db': 0, 'password': 'password', 'prefix': 'session', 'socket_timeout': 1 } Redis Sentinel ~~~~~~~~~~~~~~ .. code:: python SESSION_REDIS_SENTINEL_LIST = [(host, port), (host, port), (host, port)] SESSION_REDIS_SENTINEL_MASTER_ALIAS = 'sentinel-master' Redis Pool (Horizontal partitioning) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Splits sessions between Redis instances based on the session key. You can configure the connection type for each Redis instance in the pool (host/port, unix socket, redis url). .. code:: python SESSION_REDIS = { 'prefix': 'session', 'socket_timeout': 1 'retry_on_timeout': False, 'pool': [{ 'host': 'localhost3', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1 }, { 'host': 'localhost2', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1 }, { 'host': 'localhost1', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1 }] } Tests ===== .. code:: bash $ pip install -r dev_requirements.txt # Make sure you have redis running on localhost:6379 $ nosetests -v `Changelog `__ ============================================================================================= .. _Installation: #installation .. _Available Settings: #available-settings .. _Changelog: #changelog .. |Build Status| image:: https://travis-ci.org/martinrusev/django-redis-sessions.svg?branch=master :target: https://travis-ci.org/martinrusev/django-redis-sessionsdjango-redis-sessions-0.6.1/MANIFEST.in0000664000175000017500000000010713157721235020302 0ustar martinmartin00000000000000include README.rst include LICENSE.txt include CHANGELOG.md graft testsdjango-redis-sessions-0.6.1/setup.cfg0000664000175000017500000000007313164406470020366 0ustar martinmartin00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 django-redis-sessions-0.6.1/redis_sessions/0000775000175000017500000000000013164406470021601 5ustar martinmartin00000000000000django-redis-sessions-0.6.1/redis_sessions/__init__.py0000664000175000017500000000002613164406235023707 0ustar martinmartin00000000000000__version__ = '0.6.1' django-redis-sessions-0.6.1/redis_sessions/settings.py0000664000175000017500000000260413157211507024012 0ustar martinmartin00000000000000from django.conf import settings # SESSION_REDIS - Default SESSION_REDIS = getattr(settings, 'SESSION_REDIS', {}) SESSION_REDIS_HOST = SESSION_REDIS.get('host', 'localhost') SESSION_REDIS_PORT = SESSION_REDIS.get('port', 6379) SESSION_REDIS_SOCKET_TIMEOUT = SESSION_REDIS.get('socket_timeout', 0.1) SESSION_REDIS_RETRY_ON_TIMEOUT = SESSION_REDIS.get('retry_on_timeout', False) SESSION_REDIS_DB = SESSION_REDIS.get('db', 0) SESSION_REDIS_PREFIX = SESSION_REDIS.get('prefix', '') SESSION_REDIS_PASSWORD = SESSION_REDIS.get('password', None) SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH = SESSION_REDIS.get('unix_domain_socket_path', None) SESSION_REDIS_URL = SESSION_REDIS.get('url', None) """ Should be on the format: [ { 'host': 'localhost2', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1, }, { 'host': 'localhost1', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1, }, ] """ SESSION_REDIS_POOL = SESSION_REDIS.get('POOL', None) # should be on the format [(host, port), (host, port), (host, port)] SESSION_REDIS_SENTINEL_LIST = getattr(settings, 'SESSION_REDIS_SENTINEL_LIST', None) SESSION_REDIS_SENTINEL_MASTER_ALIAS = getattr(settings, 'SESSION_REDIS_SENTINEL_MASTER_ALIAS', None)django-redis-sessions-0.6.1/redis_sessions/session.py0000664000175000017500000001460713156707723023654 0ustar martinmartin00000000000000import redis try: from django.utils.encoding import force_unicode except ImportError: # Python 3.* from django.utils.encoding import force_text as force_unicode from django.contrib.sessions.backends.base import SessionBase, CreateError from redis_sessions import settings class RedisServer(): __redis = {} def __init__(self, session_key): self.session_key = session_key self.connection_key = '' if settings.SESSION_REDIS_SENTINEL_LIST is not None: self.connection_type = 'sentinel' else: if settings.SESSION_REDIS_POOL is not None: server_key, server = self.get_server(session_key, settings.SESSION_REDIS_POOL) self.connection_key = str(server_key) settings.SESSION_REDIS_HOST = getattr(server, 'host', 'localhost') settings.SESSION_REDIS_PORT = getattr(server, 'port', 6379) settings.SESSION_REDIS_DB = getattr(server, 'db', 0) settings.SESSION_REDIS_PASSWORD = getattr(server, 'password', None) settings.SESSION_REDIS_URL = getattr(server, 'url', None) settings.SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH = getattr(server,'unix_domain_socket_path', None) if settings.SESSION_REDIS_URL is not None: self.connection_type = 'redis_url' elif settings.SESSION_REDIS_HOST is not None: self.connection_type = 'redis_host' elif settings.SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH is not None: self.connection_type = 'redis_unix_url' self.connection_key += self.connection_type def get_server(self, key, servers_pool): total_weight = sum([row.get('weight', 1) for row in servers_pool]) pos = 0 for i in range(3, -1, -1): pos = pos * 2 ** 8 + ord(key[i]) pos = pos % total_weight pool = iter(servers_pool) server = next(pool) server_key = 0 i = 0 while i < total_weight: if i <= pos < (i + server.get('weight', 1)): return server_key, server i += server.get('weight', 1) server = next(pool) server_key += 1 return def get(self): if self.connection_key in self.__redis: return self.__redis[self.connection_key] if self.connection_type == 'sentinel': from redis.sentinel import Sentinel self.__redis[self.connection_key] = Sentinel( settings.SESSION_REDIS_SENTINEL_LIST, socket_timeout=settings.SESSION_REDIS_SOCKET_TIMEOUT, retry_on_timeout=settings.SESSION_REDIS_RETRY_ON_TIMEOUT, db=getattr(settings, 'db', 0), password=getattr(settings, 'password', None) ).master_for(settings.SESSION_REDIS_SENTINEL_MASTER_ALIAS) elif self.connection_type == 'redis_url': self.__redis[self.connection_key] = redis.StrictRedis.from_url( settings.SESSION_REDIS_URL, socket_timeout=settings.SESSION_REDIS_SOCKET_TIMEOUT ) elif self.connection_type == 'redis_host': self.__redis[self.connection_key] = redis.StrictRedis( host=settings.SESSION_REDIS_HOST, port=settings.SESSION_REDIS_PORT, socket_timeout=settings.SESSION_REDIS_SOCKET_TIMEOUT, retry_on_timeout=settings.SESSION_REDIS_RETRY_ON_TIMEOUT, db=settings.SESSION_REDIS_DB, password=settings.SESSION_REDIS_PASSWORD ) elif self.connection_type == 'redis_unix_url': self.__redis[self.connection_key] = redis.StrictRedis( unix_socket_path=settings.SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH, socket_timeout=settings.SESSION_REDIS_SOCKET_TIMEOUT, retry_on_timeout=settings.SESSION_REDIS_RETRY_ON_TIMEOUT, db=settings.SESSION_REDIS_DB, password=settings.SESSION_REDIS_PASSWORD, ) return self.__redis[self.connection_key] class SessionStore(SessionBase): """ Implements Redis database session store. """ def __init__(self, session_key=None): super(SessionStore, self).__init__(session_key) self.server = RedisServer(session_key).get() def load(self): try: session_data = self.server.get( self.get_real_stored_key(self._get_or_create_session_key()) ) return self.decode(force_unicode(session_data)) except: self._session_key = None return {} def exists(self, session_key): return self.server.exists(self.get_real_stored_key(session_key)) def create(self): while True: self._session_key = self._get_new_session_key() try: self.save(must_create=True) except CreateError: # Key wasn't unique. Try again. continue self.modified = True return def save(self, must_create=False): if self.session_key is None: return self.create() if must_create and self.exists(self._get_or_create_session_key()): raise CreateError data = self.encode(self._get_session(no_load=must_create)) if redis.VERSION[0] >= 2: self.server.setex( self.get_real_stored_key(self._get_or_create_session_key()), self.get_expiry_age(), data ) else: self.server.set( self.get_real_stored_key(self._get_or_create_session_key()), data ) self.server.expire( self.get_real_stored_key(self._get_or_create_session_key()), self.get_expiry_age() ) def delete(self, session_key=None): if session_key is None: if self.session_key is None: return session_key = self.session_key try: self.server.delete(self.get_real_stored_key(session_key)) except: pass def get_real_stored_key(self, session_key): """Return the real key name in redis storage @return string """ prefix = settings.SESSION_REDIS_PREFIX if not prefix: return session_key return ':'.join([prefix, session_key]) django-redis-sessions-0.6.1/CHANGELOG.md0000664000175000017500000000062613157211202020347 0ustar martinmartin00000000000000## 0.6.1 (16 September 2017) BUG FIXES: * Dict Config fixes: ([#48](https://github.com/martinrusev/django-redis-sessions/issues/48)) ## 0.6 (6 September 2017) IMPROVEMENTS: * Dict config: ([#18](https://github.com/martinrusev/django-redis-sessions/issues/18)) ## 0.5.6 (9 June 2016) IMPROVEMENTS: * Redis Sentinel support: ([#29](https://github.com/martinrusev/django-redis-sessions/pull/29))django-redis-sessions-0.6.1/setup.py0000664000175000017500000000166313157721252020265 0ustar martinmartin00000000000000from setuptools import setup import os from redis_sessions import __version__ def read(filename): return open(os.path.join(os.path.dirname(__file__), filename)).read() packages = ['redis_sessions'] setup( name='django-redis-sessions', version=__version__, description= "Redis Session Backend For Django", long_description=read("README.rst"), keywords='django, sessions,', author='Martin Rusev', author_email='martin@amon.cx', url='http://github.com/martinrusev/django-redis-sessions', license='BSD', packages=packages, zip_safe=False, install_requires=['redis>=2.4.10'], include_package_data=True, classifiers=[ "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules", "Framework :: Django", "Environment :: Web Environment", ], test_suite='tests' ) django-redis-sessions-0.6.1/django_redis_sessions.egg-info/0000775000175000017500000000000013164406470024615 5ustar martinmartin00000000000000django-redis-sessions-0.6.1/django_redis_sessions.egg-info/SOURCES.txt0000664000175000017500000000105113164406470026476 0ustar martinmartin00000000000000CHANGELOG.md LICENSE.txt MANIFEST.in README.rst setup.py django_redis_sessions.egg-info/PKG-INFO django_redis_sessions.egg-info/SOURCES.txt django_redis_sessions.egg-info/dependency_links.txt django_redis_sessions.egg-info/not-zip-safe django_redis_sessions.egg-info/requires.txt django_redis_sessions.egg-info/top_level.txt redis_sessions/__init__.py redis_sessions/session.py redis_sessions/settings.py tests/__init__.py tests/__init__.pyc tests/tests.py tests/tests.pyc tests/__pycache__/__init__.cpython-35.pyc tests/__pycache__/tests.cpython-35.pycdjango-redis-sessions-0.6.1/django_redis_sessions.egg-info/not-zip-safe0000664000175000017500000000000113164406470027043 0ustar martinmartin00000000000000 django-redis-sessions-0.6.1/django_redis_sessions.egg-info/dependency_links.txt0000664000175000017500000000000113164406470030663 0ustar martinmartin00000000000000 django-redis-sessions-0.6.1/django_redis_sessions.egg-info/PKG-INFO0000664000175000017500000001053613164406470025717 0ustar martinmartin00000000000000Metadata-Version: 1.1 Name: django-redis-sessions Version: 0.6.1 Summary: Redis Session Backend For Django Home-page: http://github.com/martinrusev/django-redis-sessions Author: Martin Rusev Author-email: martin@amon.cx License: BSD Description: django-redis-sessions ===================== Redis database backend for your sessions |Build Status| - `Installation`_ - `Available Settings`_ - `Changelog`_ Installation ============ - Run ``pip install django-redis-sessions`` or alternatively download the tarball and run ``python setup.py install``, For Django < 1.4 run ``pip install django-redis-sessions==0.3`` - Set ``redis_sessions.session`` as your session engine, like so: .. code:: python SESSION_ENGINE = 'redis_sessions.session' Available Settings ================== .. code:: python SESSION_REDIS = { 'host': 'localhost', 'port': 6379, 'db': 0, 'password': 'password', 'prefix': 'session', 'socket_timeout': 1 } If you prefer domain socket connection, you can just add this line instead of HOST and PORT. .. code:: python SESSION_REDIS = { 'unix_domain_socket_path': '/var/run/redis/redis.sock', 'db': 0, 'password': 'password', 'prefix': 'session', 'socket_timeout': 1 } Redis Sentinel ~~~~~~~~~~~~~~ .. code:: python SESSION_REDIS_SENTINEL_LIST = [(host, port), (host, port), (host, port)] SESSION_REDIS_SENTINEL_MASTER_ALIAS = 'sentinel-master' Redis Pool (Horizontal partitioning) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Splits sessions between Redis instances based on the session key. You can configure the connection type for each Redis instance in the pool (host/port, unix socket, redis url). .. code:: python SESSION_REDIS = { 'prefix': 'session', 'socket_timeout': 1 'retry_on_timeout': False, 'pool': [{ 'host': 'localhost3', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1 }, { 'host': 'localhost2', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1 }, { 'host': 'localhost1', 'port': 6379, 'db': 0, 'password': None, 'unix_domain_socket_path': None, 'url': None, 'weight': 1 }] } Tests ===== .. code:: bash $ pip install -r dev_requirements.txt # Make sure you have redis running on localhost:6379 $ nosetests -v `Changelog `__ ============================================================================================= .. _Installation: #installation .. _Available Settings: #available-settings .. _Changelog: #changelog .. |Build Status| image:: https://travis-ci.org/martinrusev/django-redis-sessions.svg?branch=master :target: https://travis-ci.org/martinrusev/django-redis-sessions Keywords: django,sessions, Platform: UNKNOWN Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 3 Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Framework :: Django Classifier: Environment :: Web Environment django-redis-sessions-0.6.1/django_redis_sessions.egg-info/top_level.txt0000664000175000017500000000001713164406470027345 0ustar martinmartin00000000000000redis_sessions django-redis-sessions-0.6.1/django_redis_sessions.egg-info/requires.txt0000664000175000017500000000001613164406470027212 0ustar martinmartin00000000000000redis>=2.4.10 django-redis-sessions-0.6.1/LICENSE.txt0000664000175000017500000000275713154024004020367 0ustar martinmartin00000000000000Copyright (c) 2017, Martin Rusev All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.