Looking for a quick method to reload a local or remote memcached instance? Enter Fabric.
Fabric is the Python library used to automate deployments using SSH. It is a necessary tool for every Python developer's toolbox.
Here is an example Fabric script for flushing memcached:
from fabric.api import *
# list of remote memcached servers
env.hosts = ['live',]def memcached_flush():
"""
Flush memcached on live
"""
print "Flushing memcached live"
run('echo "flush_all" | nc 127.0.0.1 11211')def memcached_flush_local():
"""
Flush local memcached
"""
print "Flushing memcached"
local('echo "flush_all" | nc 127.0.0.1 11211')
The assumption with the aforementioned code is the memcached instance is bound to 127.0.0.1 on port 11211 (the memcached default). It relies on nc (netcat) to write the flush_all command.


Comments