sessions: patch baker to take expire time for redis for auto session cleanup.
This commit is contained in:
parent
d79287cbfe
commit
5e1a429afd
3 changed files with 46 additions and 0 deletions
18
pkgs/patches/beaker/patch-beaker-improved-redis-2.diff
Normal file
18
pkgs/patches/beaker/patch-beaker-improved-redis-2.diff
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
diff -rup Beaker-1.9.1-orig/beaker/session.py Beaker-1.9.1/beaker/session.py
|
||||
--- Beaker-1.9.1-orig/beaker/session.py 2020-04-10 10:23:04.000000000 +0200
|
||||
+++ Beaker-1.9.1/beaker/session.py 2020-04-10 10:23:34.000000000 +0200
|
||||
@@ -156,6 +156,14 @@ def __init__(self, request, id=None, invalidate_corrupt=False,
|
||||
if timeout and not save_accessed_time:
|
||||
raise BeakerException("timeout requires save_accessed_time")
|
||||
self.timeout = timeout
|
||||
+ # We want to pass timeout param to redis backend to support expiration of keys
|
||||
+ # In future, I believe, we can use this param for memcached and mongo as well
|
||||
+ if self.timeout is not None and self.type == 'ext:redis':
|
||||
+ # The backend expiration should always be a bit longer (I decied to use 2 minutes) than the
|
||||
+ # session expiration itself to prevent the case where the backend data expires while
|
||||
+ # the session is being read (PR#153)
|
||||
+ self.namespace_args['timeout'] = self.timeout + 60 * 2
|
||||
+
|
||||
self.save_atime = save_accessed_time
|
||||
self.use_cookies = use_cookies
|
||||
self.cookie_expires = cookie_expires
|
||||
26
pkgs/patches/beaker/patch-beaker-improved-redis.diff
Normal file
26
pkgs/patches/beaker/patch-beaker-improved-redis.diff
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
diff -rup Beaker-1.9.1-orig/beaker/ext/redisnm.py Beaker-1.9.1/beaker/ext/redisnm.py
|
||||
--- Beaker-1.9.1-orig/beaker/ext/redisnm.py 2018-04-10 10:23:04.000000000 +0200
|
||||
+++ Beaker-1.9.1/beaker/ext/redisnm.py 2018-04-10 10:23:34.000000000 +0200
|
||||
@@ -30,9 +30,10 @@ class RedisNamespaceManager(NamespaceManager):
|
||||
|
||||
clients = SyncDict()
|
||||
|
||||
- def __init__(self, namespace, url, **kw):
|
||||
+ def __init__(self, namespace, url, timeout=None, **kw):
|
||||
super(RedisNamespaceManager, self).__init__(namespace)
|
||||
self.lock_dir = None # Redis uses redis itself for locking.
|
||||
+ self.timeout = timeout
|
||||
|
||||
if redis is None:
|
||||
raise RuntimeError('redis is not available')
|
||||
@@ -68,6 +69,8 @@ def has_key(self, key):
|
||||
|
||||
def set_value(self, key, value, expiretime=None):
|
||||
value = pickle.dumps(value)
|
||||
+ if expiretime is None and self.timeout is not None:
|
||||
+ expiretime = self.timeout
|
||||
if expiretime is not None:
|
||||
self.client.setex(self._format_key(key), int(expiretime), value)
|
||||
else:
|
||||
|
||||
|
||||
|
|
@ -32,6 +32,8 @@ self: super: {
|
|||
patches = [
|
||||
./patches/beaker/patch-beaker-lock-func-debug.diff
|
||||
./patches/beaker/patch-beaker-metadata-reuse.diff
|
||||
./patches/beaker/patch-beaker-improved-redis.diff
|
||||
./patches/beaker/patch-beaker-improved-redis-2.diff
|
||||
];
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue