##// END OF EJS Templates
user-sessions: added option to cleanup redis based sessions in user session interface.
ergo -
r3539:78388d8d default
parent child Browse files
Show More
@@ -379,6 +379,10 b' rc_cache.cache_repo_longterm.max_size = '
379 379 beaker.session.type = file
380 380 beaker.session.data_dir = %(here)s/data/sessions
381 381
382 ## redis sessions
383 #beaker.session.type = ext:redis
384 #beaker.session.url = redis://127.0.0.1:6379/2
385
382 386 ## db based session, fast, and allows easy management over logged in users
383 387 #beaker.session.type = ext:database
384 388 #beaker.session.table_name = db_session
@@ -354,6 +354,10 b' rc_cache.cache_repo_longterm.max_size = '
354 354 beaker.session.type = file
355 355 beaker.session.data_dir = %(here)s/data/sessions
356 356
357 ## redis sessions
358 #beaker.session.type = ext:redis
359 #beaker.session.url = redis://127.0.0.1:6379/2
360
357 361 ## db based session, fast, and allows easy management over logged in users
358 362 #beaker.session.type = ext:database
359 363 #beaker.session.table_name = db_session
@@ -23,6 +23,7 b' import re'
23 23 import time
24 24 import datetime
25 25 import dateutil
26 import pickle
26 27
27 28 from rhodecode.model.db import DbSession, Session
28 29
@@ -142,7 +143,6 b' class FileAuthSessions(BaseAuthSessions)'
142 143 return stats['callbacks']
143 144
144 145
145
146 146 class MemcachedAuthSessions(BaseAuthSessions):
147 147 SESSION_TYPE = 'ext:memcached'
148 148 _key_regex = re.compile(r'ITEM (.*_session) \[(.*); (.*)\]')
@@ -195,6 +195,43 b' class MemcachedAuthSessions(BaseAuthSess'
195 195 raise CleanupCommand('Cleanup for this session type not yet available')
196 196
197 197
198 class RedisAuthSessions(BaseAuthSessions):
199 SESSION_TYPE = 'ext:redis'
200
201 def _get_client(self):
202 import redis
203 args = {
204 'socket_timeout': 60,
205 'url': self.config.get('beaker.session.url')
206 }
207
208 client = redis.StrictRedis.from_url(**args)
209 return client
210
211 def get_count(self):
212 client = self._get_client()
213 return len(client.keys('beaker_cache:*'))
214
215 def get_expired_count(self, older_than_seconds=None):
216 expiry_date = self._seconds_to_date(older_than_seconds)
217 return self.NOT_AVAILABLE
218
219 def clean_sessions(self, older_than_seconds=None):
220 client = self._get_client()
221 expiry_time = time.time() - older_than_seconds
222 deleted_keys = 0
223 for key in client.keys('beaker_cache:*'):
224 data = client.get(key)
225 if data:
226 json_data = pickle.loads(data)
227 accessed_time = json_data['_accessed_time']
228 if accessed_time < expiry_time:
229 client.delete(key)
230 deleted_keys += 1
231
232 return deleted_keys
233
234
198 235 class MemoryAuthSessions(BaseAuthSessions):
199 236 SESSION_TYPE = 'memory'
200 237
@@ -212,6 +249,7 b' def get_session_handler(session_type):'
212 249 types = {
213 250 'file': FileAuthSessions,
214 251 'ext:memcached': MemcachedAuthSessions,
252 'ext:redis': RedisAuthSessions,
215 253 'ext:database': DbAuthSessions,
216 254 'memory': MemoryAuthSessions
217 255 }
General Comments 0
You need to be logged in to leave comments. Login now