summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Miu <miujerry@amazon.com>2021-04-14 13:11:57 -0700
committerGitHub <noreply@github.com>2021-04-14 13:11:57 -0700
commitf232bdd073f2326485604b690e839c46c42c60f4 (patch)
tree0cd2802e4e7cc6ccc65805cb20e76ecc471c117b
parent8781c772aceb99dcac93280a0e434888ac814e38 (diff)
downloadpymemcache-f232bdd073f2326485604b690e839c46c42c60f4.tar.gz
Removing trailing space after a command if there are no arguments. (#311)
According to the Memcached Protocol, the no argument form of the stats command should have no trailing spaces. Currently, b'stats \r\n' instead of b'stats\r\n' is being sent to the socket which leads to a malformed response.
-rw-r--r--pymemcache/client/base.py5
-rw-r--r--pymemcache/test/test_client.py4
2 files changed, 6 insertions, 3 deletions
diff --git a/pymemcache/client/base.py b/pymemcache/client/base.py
index 2b5d3a7..4db03b8 100644
--- a/pymemcache/client/base.py
+++ b/pymemcache/client/base.py
@@ -893,7 +893,10 @@ class Client(object):
remapped_keys = dict(zip(prefixed_keys, keys))
# It is important for all keys to be listed in their original order.
- cmd = name + b' ' + b' '.join(prefixed_keys) + b'\r\n'
+ cmd = name
+ if prefixed_keys:
+ cmd += b' ' + b' '.join(prefixed_keys)
+ cmd += b'\r\n'
try:
if self.sock is None:
diff --git a/pymemcache/test/test_client.py b/pymemcache/test/test_client.py
index 91655ed..bdaf233 100644
--- a/pymemcache/test/test_client.py
+++ b/pymemcache/test/test_client.py
@@ -889,7 +889,7 @@ class TestClient(ClientTestMixin, unittest.TestCase):
client = self.make_client([b'STAT fake_stats 1\r\n', b'END\r\n'])
result = client.stats()
assert client.sock.send_bufs == [
- b'stats \r\n'
+ b'stats\r\n'
]
assert result == {b'fake_stats': 1}
@@ -923,7 +923,7 @@ class TestClient(ClientTestMixin, unittest.TestCase):
])
result = client.stats()
assert client.sock.send_bufs == [
- b'stats \r\n'
+ b'stats\r\n'
]
expected = {
b'cmd_get': 2519,