redis-sessions: fixed cleanup command failing on serialized errors.
somehow beaker mangles the data when logout happens we cannot de-serialize it properly then
This commit is contained in:
parent
163ca2fb91
commit
d73dfa02a2
1 changed files with 11 additions and 1 deletions
|
|
@ -21,7 +21,9 @@ import re
|
|||
import time
|
||||
import datetime
|
||||
import dateutil
|
||||
import dateutil.relativedelta
|
||||
import pickle
|
||||
import base64
|
||||
|
||||
from rhodecode.model.db import DbSession, Session
|
||||
|
||||
|
|
@ -199,6 +201,7 @@ class RedisAuthSessions(BaseAuthSessions):
|
|||
import redis
|
||||
args = {
|
||||
'socket_timeout': 60,
|
||||
'decode_responses': False,
|
||||
'url': self.config.get('beaker.session.url')
|
||||
}
|
||||
|
||||
|
|
@ -217,14 +220,21 @@ class RedisAuthSessions(BaseAuthSessions):
|
|||
client = self._get_client()
|
||||
expiry_time = time.time() - older_than_seconds
|
||||
deleted_keys = 0
|
||||
|
||||
for key in client.keys('beaker_cache:*'):
|
||||
data = client.get(key)
|
||||
if data:
|
||||
json_data = pickle.loads(data)
|
||||
accessed_time = 0
|
||||
data = base64.b64decode(data)
|
||||
|
||||
try:
|
||||
json_data = pickle.loads(data)
|
||||
accessed_time = json_data['_accessed_time']
|
||||
except pickle.UnpicklingError:
|
||||
accessed_time = 0
|
||||
except KeyError:
|
||||
accessed_time = 0
|
||||
|
||||
if accessed_time < expiry_time:
|
||||
client.delete(key)
|
||||
deleted_keys += 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue