will.thoughts.pop
RSS icon Email icon Home icon
  • Flushing memcached servers from Ruby

    Posted on January 8th, 2010 Will No comments

    In Flushing memcached servers the easy way I highlighted a way to flush a memcached server without restarting it:

    $ echo ”flush_all” | nc localhost 11211

    However I almost never use the actual shell version of this, mostly I do the equivalent in Ruby by opening up a socket and communicating through that. Here’s a simple example:

    socket = TCPSocket.new( '127.0.0.1', 11211 )
    socket.write( "flush_all\r\n" )
    result = socket.recv(2)
    puts "Success!" if result == 'OK'
    socket.close