Memcached的 flush_all 命令用於刪除memcached伺服器中的所有資料(鍵值對)。它接受一個叫做time可選引數,表示這個時間後的所有memcached資料會被清除。
memcached 的 flush_all 命令的基本語法如下所示:
flush_all [time] [noreply]
上面的命令總是返回OK
在下面給出的例子中,我們儲存一些資料到 memcached 伺服器,然後清除所有資料。
set yiibai 0 900 9 memcached STORED get yiibai VALUE yiibai 0 9 memcached END flush_all OK get yiibai END
要清除memcached伺服器的資料,則需要使用memcached的flush 方法。
import net.spy.memcached.MemcachedClient; public class MemcachedJava { public static void main(String[] args) { //Connecting to Memcached server on localhost MemcachedClient mcc = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211)); System.out.println("Connection to server sucessfully"); System.out.println("set status:"+mcc.set("count", 900, "5").isDone()); //Get value from cache System.out.println("Get from Cache:"+mcc.get("count")); // now increase the stored value System.out.println("Increment value:"+mcc.incr("count", 2)); // now decrease the stored value System.out.println("Decrement value:"+mcc.decr("count", 1)); // now get the final stored value System.out.println("Get from Cache:"+mcc.get("count")); // now clear all this data System.out.println("Clear data:"+mcc.flush().isDone()); } }
當上述程式編譯和執行,它提供了以下的輸出:
Connection to server successfully set status:true Get from Cache:5 Increment value:7 Decrement value:6 Get from Cache:6 Clear data:true