17

I've installed memcache and now how do I really view the data in memcache?

Is there any way to see the data present in cache inside memcache?

How do I really know whether memcache is getting data stored inside it?

Note: I don't want to write any program to see the data inside memcache. Basically, memcache server is already installed in my environment and it is caching the data as well. But I would like to know if there are any utility programs available which will show me the cached data inside memcache or if there is any command which will show me the data cached so far.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Mike
  • 7,606
  • 25
  • 65
  • 82
  • For starters you need a Java-based memcached client; see http://stackoverflow.com/questions/731738/java-memcached-client – Dexygen Dec 07 '11 at 18:54
  • Do you mean I can use client to view cached data inside memcache?? – Mike Dec 07 '11 at 19:02
  • A client would seem to me to be useless if you couldn't use it for that purpose. I would suggest you research then post a new question once you are using a client, if you continue to have problems. – Dexygen Dec 07 '11 at 19:05
  • I've already installed memcache server & I just want to know if there is a way to see the cached data within it. Please see my updated edits. – Mike Dec 07 '11 at 19:07
  • possible duplicate of [What's the simplest way to get a dump of all memcached keys into a file?](http://stackoverflow.com/questions/13940404/whats-the-simplest-way-to-get-a-dump-of-all-memcached-keys-into-a-file) – kenorb Mar 09 '15 at 18:00

2 Answers2

15

There is no way to get memcached to report which keys it holds. I believe that this was a design choice as to do so would have a negative impact on performance.

However, you can use any telnet client application to connect the memcached server and type in commands. Doing this to get or set a particular key.

For example,

stats

or:

get MY_KEY
kenorb
  • 155,785
  • 88
  • 678
  • 743
Steve
  • 1,769
  • 2
  • 22
  • 33
10

To dump a list of keys from a server, use memdump tool (sometimes memcdump), e.g.

memdump --servers=localhost

To get value of item, use netcat:

echo "get 13456_-cache-some_object" | nc 127.0.0.1 11211

or in Bash:

exec {memcache}<>/dev/tcp/localhost/11211; printf "get items:42:number\nquit\n" >&${memcache}; cat <&${memcache}

To dump all objects:

memdump --servers=localhost | xargs -L1 -I% sh -c 'echo "get %" | nc localhost 11211'

or in Bash:

exec {memcache}<>/dev/tcp/localhost/11211; printf "stats items\nquit\n" >&${memcache}; cat <&${memcache}
kenorb
  • 155,785
  • 88
  • 678
  • 743