Skip to content

Commit 28f11b1

Browse files
committed
Added usage and split out keys() and key_details()
1 parent b3006b7 commit 28f11b1

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
11
# python-memcached-stats
22

33
Python class to gather stats and slab keys from memcached via the memcached telnet interface
4+
5+
## Usage
6+
7+
Usage is simple:
8+
9+
from memcached_stats import MemcachedStats
10+
mem = MemcachedStats()
11+
12+
By default, it connects to localhost on port 11211. If you need to specify a host and/or port:
13+
14+
mem = MemcachedStats('1.2.3.4', '11211')
15+
16+
Retrieve a dict containing the current stats from memcached:
17+
18+
>>> mem.stats()
19+
{'accepting_conns': '1',
20+
'auth_cmds': '0',
21+
'auth_errors': '0',
22+
... }
23+
24+
Retrieve a list of keys currently in use:
25+
26+
>>> mem.keys()
27+
['key-1',
28+
'key-2',
29+
'key-3',
30+
... ]

src/memcached_stats.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def client(self):
1414
self._client = telnetlib.Telnet(self._host, self._port)
1515
return self._client
1616

17-
def keys(self, sort=True):
18-
' Return a list of keys in use '
17+
def key_details(self, sort=True):
18+
' Return a list of tuples containing keys and details '
1919
keys = []
2020
slab_ids = self.slab_ids()
2121
for id in slab_ids:
@@ -26,6 +26,10 @@ def keys(self, sort=True):
2626
return sorted(keys)
2727
return keys
2828

29+
def keys(self, sort=True):
30+
' Return a list of keys in use '
31+
return [key[0] for key in self.key_details(sort=sort)]
32+
2933
def slab_ids(self):
3034
' Return a list of slab ids in use '
3135
self.client.write("stats items\n")

0 commit comments

Comments
 (0)