Skip to content

Commit e708722

Browse files
skywaymsnmethane
authored andcommitted
multi-server support with HashClient (#1)
1 parent c070e40 commit e708722

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

flask_pymemcache.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from __future__ import absolute_import, division, print_function
5858
import flask
5959
import pymemcache.client
60+
import pymemcache.client.hash
6061

6162

6263
class FlaskPyMemcache(object):
@@ -82,7 +83,15 @@ def init_app(self, app, conf_key=None):
8283
raise TypeError("Flask-PyMemcache conf should be dict")
8384

8485
close_on_teardown = conf.pop('close_on_teardown', False)
85-
client = pymemcache.client.Client(**conf)
86+
87+
if isinstance(conf['server'], list):
88+
conf['servers'] = conf.pop('server')
89+
client = pymemcache.client.hash.HashClient(**conf)
90+
elif isinstance(conf['server'], tuple):
91+
client = pymemcache.client.Client(**conf)
92+
else:
93+
raise TypeError("Flask-PyMemcache conf['server'] should be tuple or list of tuples")
94+
8695
app.extensions.setdefault('pymemcache', {})
8796
app.extensions['pymemcache'][self] = client
8897

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
url='https://github.com/KLab/Flask-PyMemcache',
2020
description="pymemcache integration for Flask",
2121
long_description=readme,
22-
install_requires=["Flask", "pymemcache>=1.2.3", "six"],
22+
install_requires=["Flask", "pymemcache>=1.3.4", "six"],
2323
test_require=['pytest'],
2424
test_suite='test_flask_pymemcache',
2525
)

0 commit comments

Comments
 (0)