Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding redis session pool and migration script for sessions.

  • Loading branch information...
commit 095ceef45a8360bbcbe205564be73969e901dcf9 1 parent 4b8b958
@samuelclay authored
Showing with 18 additions and 0 deletions.
  1. +1 −0  settings.py
  2. +17 −0 utils/bootstrap_redis_sessions.py
View
1  settings.py
@@ -544,6 +544,7 @@ def custom_show_toolbar(request):
REDIS_POOL = redis.ConnectionPool(host=REDIS['host'], port=6379, db=0)
REDIS_STORY_POOL = redis.ConnectionPool(host=REDIS['host'], port=6379, db=1)
REDIS_ANALYTICS_POOL = redis.ConnectionPool(host=REDIS['host'], port=6379, db=2)
+REDIS_SESSION_POOL = redis.ConnectionPool(host=REDIS['host'], port=6379, db=5)
JAMMIT = jammit.JammitAssets(NEWSBLUR_DIR)
View
17 utils/bootstrap_redis_sessions.py
@@ -0,0 +1,17 @@
+import math
+import redis
+from django.conf import settings
+from django.contrib.sessions.models import Session
+
+sessions_count = Session.objects.count()
+print " ---> %s sessions in Django" % sessions_count
+batch_size = 100
+r = redis.Redis(connection_pool=settings.REDIS_SESSION_POOL)
+
+for batch in range(int(math.ceil(sessions_count / batch_size))+1):
+ start = batch * batch_size
+ end = (batch + 1) * batch_size
+ print " ---> Loading sessions #%s - #%s" % (start, end)
+ for session in Session.objects.all()[start:end]:
+ _ = r.set(session.session_key, session.session_data)
+ _ = r.expire(session.session_key, session.expire_date.strftime("%s"))
Please sign in to comment.
Something went wrong with that request. Please try again.