Skip to content

Commit

Permalink
Create ConnectionPool in setup()
Browse files Browse the repository at this point in the history
Suggested in #11
  • Loading branch information
sc68cal committed Feb 29, 2012
1 parent dd10cd1 commit 8c3276e
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions bottle_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@ def setup(self,app):
if other.keyword == self.keyword:
raise PluginError("Found another redis plugin with "\
"conflicting settings (non-unique keyword).")
if self.redisdb is None:
self.redisdb = redis.ConnectionPool(host=self.host, port=self.port, db=self.database)

def apply(self,callback,context):
conf = context['config'].get('redis') or {}
database = conf.get('rdb',self.database)
host = conf.get('host',self.host)
port = conf.get('port',self.port)
keyword = conf.get('keyword',self.keyword)

args = inspect.getargspec(context['callback'])[0]
keyword = conf.get('keyword',self.keyword)
if keyword not in args:
return callback

if self.redisdb is None:
self.redisdb = redis.ConnectionPool(host=host, port=port, db=database)

def wrapper(*args,**kwargs):
kwargs[self.keyword] = redis.Redis(connection_pool=self.redisdb)
rv = callback(*args, **kwargs)
Expand Down

0 comments on commit 8c3276e

Please sign in to comment.