Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow NoSQL backends to accept an expire argument #15

Merged
merged 1 commit into from

3 participants

@XiaonuoGantan

Allow NoSqlManager to accept a new keyword argument expire, which is
accepted as an optional argument by the method set_value in redis.py to
specify the expire time in seconds for the session object.

@XiaonuoGantan XiaonuoGantan Add a new keyword argument expiretime to nosql.py
Allow NoSqlManager to accept a new keyword argument expire, which is
accepted as an optional argument by the method set_value in redis.py to
specify the expire time in seconds for the session object
d14f43e
@dairiki

I'm using server side beaker sessions, with (thanks to beaker_extensions) data in redis. I would like to set a redis-side expiration on the session data so that I don't have to explicitly garbage collect stale sessions.

This seems like the solution (or, at least, a solution). Or is there a better way?

@didip didip merged commit b45b10d into didip:master
@dairiki

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2012
  1. @XiaonuoGantan

    Add a new keyword argument expiretime to nosql.py

    XiaonuoGantan authored
    Allow NoSqlManager to accept a new keyword argument expire, which is
    accepted as an optional argument by the method set_value in redis.py to
    specify the expire time in seconds for the session object
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 2 deletions.
  1. +2 −0  .gitignore
  2. +4 −2 beaker_extensions/nosql.py
View
2  .gitignore
@@ -1,3 +1,5 @@
*.py?
*.egg-info
*.swp
+build/
+dist/
View
6 beaker_extensions/nosql.py
@@ -13,7 +13,7 @@
log = logging.getLogger(__name__)
class NoSqlManager(NamespaceManager):
- def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
+ def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, expire=None, **params):
NamespaceManager.__init__(self, namespace)
if not url:
@@ -26,6 +26,8 @@ def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
if hasattr(self, 'lock_dir'):
verify_directory(self.lock_dir)
+ self._expiretime = int(expire) if expire else None
+
conn_params = {}
parts = url.split('?', 1)
url = parts[0]
@@ -60,7 +62,7 @@ def set_value(self, key, value):
self.db_conn[self._format_key(key)] = pickle.dumps(value)
def __setitem__(self, key, value):
- self.set_value(key, value)
+ self.set_value(key, value, self._expiretime)
def __delitem__(self, key):
del self.db_conn[self._format_key(key)]
Something went wrong with that request. Please try again.