django的redis会话后端
django-redis-sessions的Python项目详细描述
安装
- 运行pip install django-redis-sessions或下载 tarball和runpython setup.py install,
对于django<;1.4,运行pip install django-redis-sessions==0.3
- 将redis_sessions.session设置为会话引擎,如下所示:
SESSION_ENGINE='redis_sessions.session'
可用设置
SESSION_REDIS={'host':'localhost','port':6379,'db':0,'password':'password','prefix':'session','socket_timeout':1}
如果您喜欢域套接字连接,只需添加这一行 而不是主机和端口。
SESSION_REDIS={'unix_domain_socket_path':'/var/run/redis/redis.sock','db':0,'password':'password','prefix':'session','socket_timeout':1}
redis哨兵
SESSION_REDIS_SENTINEL_LIST=[(host,port),(host,port),(host,port)]SESSION_REDIS_SENTINEL_MASTER_ALIAS='sentinel-master'
redis池(水平分区)
基于会话密钥在redis实例之间拆分会话。你 可以为池中的每个redis实例配置连接类型 (主机/端口、Unix套接字、Redis URL)。
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}]}
测试
$ pip install -r dev_requirements.txt
# Make sure you have redis running on localhost:6379
$ nosetests -v