If you use Memcached server to store application data, you may want to invalidate it once you deploy a new version to avoid corruption or weird results… In this article, I’ll show you How do I flush the entire contents of a Memcached server ?
Using telnet command
I often use telnet to flush the entire contents of Memcached server, type the following command
# 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.
– localhost: Memcached server instance
– 11211: Memcached server port
Using netcat 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.
Restart Memcached Server
Login as root and type the following command
# /etc/init.d/memcached restart
Restarting your application is not ideal however, you will lose anything cached in memory, cause delays to users trying to access your site, that sort of thing.
Using PHP script
Create php file with the following content
# vi flush_memcached.php $memcache = new Memcache; $memcache->connect('localhost', 11211); $memcache->flush();
To execute this script, type the following command
# php flush_memcached.php
- Repel port flood by CSF and IPT_Recent
- How To Display All Cron Jobs On Linux
- How To Extract RAR Files Under Linux
- Linux Password Protect Files
- How To Find Hard Drive Specifications
- 10 lsof Command Examples
- How To Install Monit On Centos / Redhat
- Setting Up An SSH Certificate
- How To Install Subversion (SVN) Extension Working With PHP 5.3
- How To Setup Iptables Firewall For A Web Server On CentOS