mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Adding redis session pool and migration script for sessions.
This commit is contained in:
parent
4b8b958078
commit
095ceef45a
2 changed files with 18 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
17
utils/bootstrap_redis_sessions.py
Normal file
17
utils/bootstrap_redis_sessions.py
Normal 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"))
|
Loading…
Add table
Reference in a new issue