Commits

Alen Mujezinovic  committed 73c4eb3

Configurable session key in redis

  • Participants
  • Parent commits 010629f

Comments (0)

Files changed (1)

File redis_sessions/backends/redis.py

+from django.conf import settings
 from django.contrib.sessions.backends.base import SessionBase, CreateError
 from redis_sessions import database as db
 
+SESSION_KEY = getattr(settings,'REDIS_SESSION_KEY','session:%(session_key)s')
 
 class SessionStore(SessionBase):
     """
     """
 
     def exists(self, session_key):
-        if db.exists("session:%s" % session_key):
+        if db.exists(SESSION_KEY % dict(session_key = session_key)):
             return True
         return False
 
             func = db.setnx
         else:
             func = db.set
-        key = "session:%s" % self.session_key
+        key = SESSION_KEY % dict(session_key = self.session_key)
         result = func(
                 key,
                 self.encode(self._get_session(no_load=must_create)))
     def delete(self, session_key=None):
         if session_key is None:
             session_key = self.session_key
-        db.delete("session:%s" % session_key)
+        db.delete(SESSION_KEY % dict(session_key = session_key))
 
     def load(self):
-        session_data = db.get("session:%s" % self.session_key)
+        session_data = db.get(SESSION_KEY % dict(session_key = self.session_key))
         if session_data is None:
             self.create()
             return {}