Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UNIX socket support for redis session store #58

Open
wants to merge 2 commits into
base: 10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions smile_redis_session_store/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ You need to install package `redis`::

pip install redis

.. _`Redis website`: http://redis.io/topics/quickstart
.. _`Redis website`: http://redis.io/topics/quickstart


Usage
=====

To use Redis, install this module and please add `enable_redis = True` option
in configuration file.
in configuration file.

Available options
-----------------
Expand All @@ -41,7 +41,9 @@ Available options
* `redis_port` (default: 6379): Redis port
* `redis_dbindex` (default: 1): Redis database index
* `redis_pass` (default: None): Redis password
* `redis_socket` (default: None) : unix socket path

If `redis_socket` is used, both `redis_host` and `redis_port` should be None.

Bug Tracker
===========
Expand Down Expand Up @@ -79,4 +81,4 @@ Since 1991 Smile has been a pioneer of technology and also the European expert i

This module is part of the `odoo-addons <https://github.com/Smile-SA/odoo_addons>`_ project on GitHub.

You are welcome to contribute.
You are welcome to contribute.
10 changes: 8 additions & 2 deletions smile_redis_session_store/redis_session_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ def __init__(self, *args, **kwargs):
super(RedisSessionStore, self).__init__(*args, **kwargs)
self.expire = kwargs.get('expire', SESSION_TIMEOUT)
self.key_prefix = kwargs.get('key_prefix', '')
_port = tools.config.get('redis_port', 6379)
try:
_port = int(_port)
except ValueError:
_port = None
self.redis = redis.Redis(host=tools.config.get('redis_host', 'localhost'),
port=int(tools.config.get('redis_port', 6379)),
port=_port,
db=int(tools.config.get('redis_dbindex', 1)),
password=tools.config.get('redis_pass', None))
password=tools.config.get('redis_pass', None),
unix_socket_path=tools.config.get('redis_socket', None))
self._is_redis_server_running()

def save(self, session):
Expand Down
36 changes: 30 additions & 6 deletions smile_redis_session_store/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<title>Redis Session Store</title>
<style type="text/css">

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 7614 2013-02-21 15:55:51Z milde $
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Expand Down Expand Up @@ -37,6 +37,14 @@
.hidden {
display: none }

.subscript {
vertical-align: sub;
font-size: smaller }

.superscript {
vertical-align: super;
font-size: smaller }

a.toc-backref {
text-decoration: none ;
color: black }
Expand Down Expand Up @@ -161,12 +169,12 @@
hr.docutils {
width: 75% }

img.align-left, .figure.align-left, object.align-left {
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }

img.align-right, .figure.align-right, object.align-right {
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
Expand All @@ -177,6 +185,11 @@
margin-right: auto;
}

table.align-center {
margin-left: auto;
margin-right: auto;
}

.align-left {
text-align: left }

Expand All @@ -194,6 +207,15 @@
/* div.align-center * { */
/* text-align: left } */

.align-top {
vertical-align: top }

.align-middle {
vertical-align: middle }

.align-bottom {
vertical-align: bottom }

ol.simple, ul.simple {
margin-bottom: 1em }

Expand Down Expand Up @@ -348,9 +370,9 @@ <h1 class="title">Redis Session Store</h1>
<h1>Requirements</h1>
<p>You need to install and to start a Redis server to use this module.
Documentation is available on <a class="reference external" href="http://redis.io/topics/quickstart">Redis website</a>.</p>
<p>You need to install package <cite>python-redis</cite>:</p>
<p>You need to install package <cite>redis</cite>:</p>
<pre class="literal-block">
apt-get install python-redis
pip install redis
</pre>
</div>
<div class="section" id="usage">
Expand All @@ -364,7 +386,9 @@ <h2>Available options</h2>
<li><cite>redis_port</cite> (default: 6379): Redis port</li>
<li><cite>redis_dbindex</cite> (default: 1): Redis database index</li>
<li><cite>redis_pass</cite> (default: None): Redis password</li>
<li><cite>redis_socket</cite> (default: None) : unix socket path</li>
</ul>
<p>If <cite>redis_socket</cite> is used, both <cite>redis_host</cite> and <cite>redis_port</cite> should be None.</p>
</div>
</div>
<div class="section" id="bug-tracker">
Expand Down