Permalink
Browse files

Accepting 'max_connections' setting for Redis connection pooling

  • Loading branch information...
1 parent 69b6664 commit e79fc19c077e1ce7b3d1e8f1ade285a4c6c2526c @diogobaeder committed Mar 11, 2013
Showing with 17 additions and 2 deletions.
  1. +8 −1 pycket/driver.py
  2. +2 −1 setup.cfg
  3. +7 −0 tests/test_driver.py
View
9 pycket/driver.py
@@ -49,7 +49,14 @@ def _set_and_expire(self, session_id, pickled_session):
def _create_client(self):
import redis
- self.client = redis.Redis(**self.settings)
+ if 'max_connections' in self.settings:
+ connection_pool = redis.ConnectionPool(**self.settings)
+ settings = copy(self.settings)
+ del settings['max_connections']
+ settings['connection_pool'] = connection_pool
+ else:
+ settings = self.settings
+ self.client = redis.Redis(**settings)
class MemcachedDriver(Driver):
View
3 setup.cfg
@@ -7,4 +7,5 @@ cover-erase=1
cover-min-percentage=100
cover-package=pycket
with-yanc=1
-with-xtraceback=1
+with-xtraceback=1
+nocapture=1
View
7 tests/test_driver.py
@@ -68,6 +68,13 @@ def starts_with_1_day_to_expire_in_database(self):
self.assertEqual(driver.EXPIRE_SECONDS, one_day)
+ @istest
+ def starts_with_max_connections(self):
+ driver = RedisDriver(dict(db=0, max_connections=123))
+ driver.get('some session')
+
+ self.assertEqual(driver.client.connection_pool.max_connections, 123)
+
class MemcachedTestCase(TestCase):
client = None

0 comments on commit e79fc19

Please sign in to comment.