Java应用程序使用清除数据
要从Memcached服务器清除数据,您需要使用Memcached flush方法。
import java.io.IOException;
import java.net.InetSocketAddress;
import net.spy.memcached.MemcachedClient;
public class MemcachedJava {
public static void main(String[] args) {
// Connecting to Memcached server on localhost
MemcachedClient mcc = null;
try {
mcc = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("Connection to server sucessfully");
System.out.println(mcc.set("jc2182",900,"memcached").getStatus());
System.out.println("Get Date::"+ mcc.get("jc2182"));
// 清除数据
System.out.println("Clear Data::" + mcc.flush().getStatus());
System.out.println("Get Date Again::"+ mcc.get("jc2182"));
}
}
在编译和执行程序时,您将看到以下输出-
Connection to server sucessfully
{OperationStatus success=true: STORED}
Get Date::memcached
Clear Data::{OperationStatus success=true: OK}
Get Date Again::null