mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-04-13 09:42:01 +00:00
20 lines
733 B
Python
20 lines
733 B
Python
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 = 1000
|
|
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]:
|
|
_ = pipe.set(session.session_key, session.session_data)
|
|
_ = pipe.expireat(session.session_key, session.expire_date.strftime("%s"))
|
|
_ = pipe.execute()
|