Adding redis session pool and migration script for sessions.

This commit is contained in:
Samuel Clay 2013-03-20 19:45:39 -07:00
parent 4b8b958078
commit 095ceef45a
2 changed files with 18 additions and 0 deletions

View file

@ -544,6 +544,7 @@ MONGOANALYTICSDB = connect(MONGO_ANALYTICS_DB.pop('name'), **MONGO_ANALYTICS_DB)
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 file

@ -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"))