Skip to content

Commit

Permalink
Issue #284 Handle ssl connections
Browse files Browse the repository at this point in the history
* `RedisPublisher` handles `ssl` flag
* Update docs
  • Loading branch information
gtnx committed May 25, 2019
1 parent db44608 commit 3332bf7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ override these values
.. note:: Specify only the values, which deviate from the default.

If your Redis instance requires a SSL connection, set the ``ssl`` flag to ``True``:

.. code-block:: python
WS4REDIS_CONNECTION = {
...
'ssl': True
}
If your Redis instance is accessed via a Unix Domain Socket, you can configure that as well:

.. code-block:: python
Expand Down
16 changes: 14 additions & 2 deletions ws4redis/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from ws4redis import settings
from ws4redis.redis_store import RedisStore
from ws4redis._compat import is_authenticated
from redis.connection import UnixDomainSocketConnection
from redis.connection import (
UnixDomainSocketConnection,
Connection,
SSLConnection,
)

if 'unix_socket_path' in settings.WS4REDIS_CONNECTION:
# rename 'unix_socket_path' to 'path' and pass as args
Expand All @@ -12,7 +16,15 @@
del conn_args['unix_socket_path']
redis_connection_pool = ConnectionPool(connection_class=UnixDomainSocketConnection, **conn_args)
else:
redis_connection_pool = ConnectionPool(**settings.WS4REDIS_CONNECTION)
conn_args = dict(settings.WS4REDIS_CONNECTION)
if conn_args.pop("ssl", None):
connection_class = SSLConnection
else:
connection_class = Connection
redis_connection_pool = ConnectionPool(
connection_class=connection_class, **conn_args
)


class RedisPublisher(RedisStore):
def __init__(self, **kwargs):
Expand Down

0 comments on commit 3332bf7

Please sign in to comment.