martinrusev / django-redis-sessions

Session backend for Django that stores sessions in a Redis database
BSD 3-Clause "New" or "Revised" License
495 stars 106 forks source link

Domain Socket connection config is broken. #56

Closed ghost closed 6 years ago

ghost commented 6 years ago

It defaults to a tcp connection even when the unix_domain_socket_path is specified as the redis_host parameter is not None since it sets itself to localhost due to the line.

SESSION_REDIS_HOST = SESSION_REDIS.get('host', 'localhost')

For domain socket connection to work, either the host parameter should be explicitly set to None or the following lines in sessions.py could be changed,

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'

to,

if settings.SESSION_REDIS_URL is not None:
         self.connection_type = 'redis_url'
elif settings.SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH is not None:
          self.connection_type = 'redis_unix_url'
elif settings.SESSION_REDIS_HOST is not None:
          self.connection_type = 'redis_host'

This way, we check for the unix_domain_socket_path before the redis_host.