How to flush the contents of Memcached
I often see people using telnet to flush the entire contents of their Memcached instance.
They use the following commands:
$ telnet localhost 11211 Trying 127.0.0.1… Connected to localhost. Escape character is ‘^]’. flush_all OK quit Connection to localhost closed by foreign host. $
You have to log in into the appropriate memcached host and port with telnet. After logged in, you have to use the flush_all command. If this command responses with OK, everything went fine and you can log out of your memcached server using the command quit.
The above command works fine but is a pain in the ass if you have to flush a lot and wants to use your console for other things.
If this is the case, you can run a flush_all in 1 command
echo 'flush_all' | nc localhost 11211
By default, nc (or netcat) creates a TCP socket either in listening mode (server socket) or a socket that is used in order to connect to a server (client mode). Actually, netcat does not care whether the socket is meant to be a server or a client. All it does is to take the data from stdin and transfer it to the other end across the network.