Skip to content

Commit

Permalink
Merge pull request #40 from agoragames/connection-pool-options
Browse files Browse the repository at this point in the history
Allow options to be passed down to the connection pool. Release 3.5.0.
  • Loading branch information
czarneckid committed Dec 11, 2015
2 parents 4783ffc + a3d38f1 commit bc77e3d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG

## 3.5.0 (2015-12-11)

* Allow options to be passed down to the connection pool.

## 3.4.0 (2015-06-16)

* Allow a Redis connection to be passed in the Leaderboard initializer using the `redis_connection` option.
Expand Down
13 changes: 8 additions & 5 deletions leaderboard/leaderboard.py
Expand Up @@ -14,13 +14,14 @@ def grouper(n, iterable, fillvalue=None):


class Leaderboard(object):
VERSION = '3.4.0'
VERSION = '3.5.0'
DEFAULT_PAGE_SIZE = 25
DEFAULT_REDIS_HOST = 'localhost'
DEFAULT_REDIS_PORT = 6379
DEFAULT_REDIS_DB = 0
DEFAULT_MEMBER_DATA_NAMESPACE = 'member_data'
DEFAULT_GLOBAL_MEMBER_DATA = False
DEFAULT_POOLS = {}
ASC = 'asc'
DESC = 'desc'
MEMBER_KEY = 'member'
Expand All @@ -29,15 +30,15 @@ class Leaderboard(object):
RANK_KEY = 'rank'

@classmethod
def pool(self, host, port, db, pools={}):
def pool(self, host, port, db, pools={}, **options):
'''
Fetch a redis conenction pool for the unique combination of host
and port. Will create a new one if there isn't one already.
'''
key = (host, port, db)
rval = pools.get(key)
if not isinstance(rval, ConnectionPool):
rval = ConnectionPool(host=host, port=port, db=db)
rval = ConnectionPool(host=host, port=port, db=db, **options)
pools[key] = rval

return rval
Expand Down Expand Up @@ -77,7 +78,7 @@ def __init__(self, leaderboard_name, **options):

redis_connection = self.options.pop('redis_connection', None)
if redis_connection:
# allow the developer to pass a raw redis connection and
# allow the developer to pass a raw redis connection and
# we will use it directly instead of creating a new one
self.redis_connection = redis_connection
else:
Expand All @@ -88,7 +89,9 @@ def __init__(self, leaderboard_name, **options):
self.options['connection_pool'] = self.pool(
self.options.pop('host', self.DEFAULT_REDIS_HOST),
self.options.pop('port', self.DEFAULT_REDIS_PORT),
self.options.pop('db', self.DEFAULT_REDIS_DB)
self.options.pop('db', self.DEFAULT_REDIS_DB),
self.options.pop('pools', self.DEFAULT_POOLS),
**self.options
)
self.redis_connection = Redis(**self.options)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -9,7 +9,7 @@

setup(
name = 'leaderboard',
version = "3.4.0",
version = "3.5.0",
author = 'David Czarnecki',
author_email = "dczarnecki@agoragames.com",
packages = ['leaderboard'],
Expand Down
2 changes: 1 addition & 1 deletion test/leaderboard/leaderboard_test.py
Expand Up @@ -18,7 +18,7 @@ def tearDown(self):
Leaderboard.MEMBER_DATA_KEY = 'member_data'

def test_version(self):
Leaderboard.VERSION.should.equal('3.4.0')
Leaderboard.VERSION.should.equal('3.5.0')

def test_init_with_defaults(self):
'name'.should.equal(self.leaderboard.leaderboard_name)
Expand Down

0 comments on commit bc77e3d

Please sign in to comment.