问题
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.
回答1:
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
回答2:
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}
来源:https://stackoverflow.com/questions/8420776/how-do-i-view-the-data-in-memcache