Skip to content

Commit ac9fea9

Browse files
author
Jon Wayne Parrott
committed
Moving managedvms/memcache to pymemcache for better python3 support.
1 parent 33cd2a9 commit ac9fea9

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed

managed_vms/memcache/main.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@
1515
import os
1616

1717
from flask import Flask
18-
import memcache
18+
from pymemcache.client.base import Client as MemcacheClient
1919

2020

2121
app = Flask(__name__)
2222

2323

2424
# [START client]
2525
memcache_addr = os.environ.get('MEMCACHE_PORT_11211_TCP_ADDR', 'localhost')
26-
memcache_port = os.environ.get('MEMCACHE_PORT_11211_TCP_PORT', '11211')
27-
memcache_client = memcache.Client([
28-
'{}:{}'.format(memcache_addr, memcache_port)])
26+
memcache_port = os.environ.get('MEMCACHE_PORT_11211_TCP_PORT', 11211)
27+
memcache_client = MemcacheClient((memcache_addr, int(memcache_port)))
2928
# [END client]
3029

3130

@@ -37,7 +36,7 @@ def index():
3736
if not memcache_client.get('counter'):
3837
memcache_client.set('counter', 0)
3938

40-
value = memcache_client.incr('counter')
39+
value = memcache_client.incr('counter', 1)
4140

4241
return 'Value is {}'.format(value)
4342
# [END example]

managed_vms/memcache/main_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818

1919
def test_index():
20-
main.memcache_client.set('counter', 0)
21-
22-
if main.memcache_client.get('counter') is None:
20+
try:
21+
main.memcache_client.set('counter', 0)
22+
except Exception:
2323
pytest.skip('Memcache is unavailable.')
2424

2525
main.app.testing = True

managed_vms/memcache/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==0.10.1
22
gunicorn==19.4.5
3-
python-memcached==1.57
3+
pymemcache==1.3.5

requirements-py27-dev.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
gcloud==0.10.1
2+
google-api-python-client==1.5.0
3+
oauth2client==2.0.0.post1
4+
requests[security]==2.9.1
15
beautifulsoup4==4.4.1
26
coverage==4.1b2
37
Flask==0.10.1
@@ -18,7 +22,7 @@ Werkzeug==0.11.4
1822
nose-timer==0.6.0
1923
Flask-SQLAlchemy==2.1
2024
PyMySQL==0.7.1
21-
python-memcached==1.57
25+
pymemcache==1.3.5
2226
PyCrypto==2.6.1
2327
flaky==3.1.0
2428
Django==1.9.2

requirements-py34-dev.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
gcloud==0.10.1
2+
google-api-python-client==1.5.0
3+
oauth2client==2.0.0.post1
4+
requests[security]==2.9.1
15
beautifulsoup4==4.4.1
26
coverage==4.1b2
37
Flask==0.10.1
@@ -18,7 +22,7 @@ Werkzeug==0.11.4
1822
nose-timer==0.6.0
1923
Flask-SQLAlchemy==2.1
2024
PyMySQL==0.7.1
21-
python-memcached==1.57
25+
pymemcache==1.3.5
2226
PyCrypto==2.6.1
2327
flaky==3.1.0
2428
Django==1.9.2

requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

tox.ini

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ envlist = pep8, py27, py34, gae
55
[testenv]
66
passenv = *
77
basepython = python2.7
8-
deps =
9-
-rrequirements.txt
108
examples =
119
bigquery/api
1210
blog/introduction_to_data_models_in_cloud_datastore
@@ -38,7 +36,6 @@ commands =
3836

3937
[testenv:py27]
4038
deps =
41-
{[testenv]deps}
4239
-rrequirements-py27-dev.txt
4340
commands =
4441
python scripts/run-tests.py {posargs:{[testenv]examples}}
@@ -55,7 +52,6 @@ commands =
5552
[testenv:py34]
5653
basepython = python3.4
5754
deps =
58-
{[testenv]deps}
5955
-rrequirements-py34-dev.txt
6056
commands =
6157
python scripts/run-tests.py {posargs:{[testenv]examples}}
@@ -72,7 +68,6 @@ commands =
7268

7369
[testenv:gae]
7470
deps =
75-
{[testenv]deps}
7671
-rrequirements-py27-dev.txt
7772
examples =
7873
appengine/app_identity/signing

0 commit comments

Comments
 (0)