Merge lp:~klaussfreire/python-memcached/python-memcached into lp:python-memcached

Proposed by klauss
Status: Needs review
Proposed branch: lp:~klaussfreire/python-memcached/python-memcached
Merge into: lp:python-memcached
Diff against target: 53 lines (+17/-2)
1 file modified
memcache.py (+17/-2)
To merge this branch: bzr merge lp:~klaussfreire/python-memcached/python-memcached
Reviewer Review Type Date Requested Status
Python Memcached Team Pending
Review via email: mp+281265@code.launchpad.net

This proposal supersedes a proposal from 2015-05-09.

Description of the change

Implements ElastiCache's "config get" command.
Useful since EC is almost memcache, so having python-memcached support it is probably the best in terms of maintainability.
EC's "config get" is just a get with another name, really. So the implementation works like that, reusing most of the code.

To post a comment you must log in.

Unmerged revisions

60. By klauss

Must catch NameError, not AttributeError

59. By klauss

Make sure python 2.x uses xrange instead of range (slow and potentially memory hungry if server weight were high)

58. By klauss

Implement ElastiCache's "config get" command (useful for working with ElastiCache clusters)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'memcache.py'
2--- memcache.py 2012-04-11 06:07:54 +0000
3+++ memcache.py 2015-12-23 02:30:58 +0000
4@@ -52,6 +52,11 @@
5 import cPickle as pickle
6 except ImportError:
7 import pickle
8+try:
9+ # Python2 should use the generator version
10+ range = xrange
11+except NameError:
12+ pass
13
14 from binascii import crc32 # zlib version is not cross-platform
15 def cmemcache_hash(key):
16@@ -836,6 +841,9 @@
17 raise_exception=True)
18 if rkey and self.cache_cas:
19 self.cas_ids[rkey] = cas_id
20+ elif cmd == 'config get':
21+ rkey, flags, rlen, = self._expectvalue(server,
22+ raise_exception=True, tag='CONFIG', taglen=6)
23 else:
24 rkey, flags, rlen, = self._expectvalue(server,
25 raise_exception=True)
26@@ -872,6 +880,13 @@
27 '''
28 return self._get('get', key)
29
30+ def get_config(self, key):
31+ '''Retrieves a key from the memcache.
32+
33+ @return: The value or None.
34+ '''
35+ return self._get('config get', key)
36+
37 def gets(self, key):
38 '''Retrieves a key from the memcache. Used in conjunction with 'cas'.
39
40@@ -961,11 +976,11 @@
41 else:
42 return (None, None, None, None)
43
44- def _expectvalue(self, server, line=None, raise_exception=False):
45+ def _expectvalue(self, server, line=None, raise_exception=False, tag="VALUE", taglen=5):
46 if not line:
47 line = server.readline(raise_exception)
48
49- if line and line[:5] == 'VALUE':
50+ if line and line[:taglen] == tag:
51 resp, rkey, flags, len = line.split()
52 flags = int(flags)
53 rlen = int(len)

Subscribers

People subscribed via source and target branches

to all changes: