mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-11-01 09:09:51 +00:00
Using redis pipeline for speeeeed in django db sessions -> redis sessions.
This commit is contained in:
parent
095ceef45a
commit
bb6aac3b35
1 changed files with 5 additions and 3 deletions
|
|
@ -5,13 +5,15 @@ from django.contrib.sessions.models import Session
|
|||
|
||||
sessions_count = Session.objects.count()
|
||||
print " ---> %s sessions in Django" % sessions_count
|
||||
batch_size = 100
|
||||
batch_size = 10
|
||||
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)
|
||||
pipe = r.pipeline()
|
||||
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"))
|
||||
_ = pipe.set(session.session_key, session.session_data)
|
||||
_ = pipe.expireat(session.session_key, session.expire_date.strftime("%s"))
|
||||
_ = pipe.execute()
|
||||
Loading…
Add table
Reference in a new issue