Memcached 简明教程
Memcached - Delete Key
Memcached delete 命令用于从 Memcached 服务器中删除现有密钥。
Syntax
Memcached delete 命令的基本语法如下所示:
delete key [noreply]
Delete Data Using Java Application
若要从 Memcached 服务器删除数据,您需要使用 Memcached delete 方法。
Example
import java.net.InetSocketAddress;
import java.util.concurrent.Future;
import net.spy.memcached.MemcachedClient;
public class MemcachedJava {
public static void main(String[] args) {
try{
// Connecting to Memcached server on localhost
MemcachedClient mcc = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));
System.out.println("Connection to server sucessful.");
// add data to memcached server
Future fo = mcc.set("tutorialspoint", 900, "World's largest online tutorials library");
// print status of set method
System.out.println("set status:" + fo.get());
// retrieve and check the value from cache
System.out.println("tutorialspoint value in cache - " + mcc.get("tutorialspoint"));
// try to add data with existing key
Future fo = mcc.delete("tutorialspoint");
// print status of delete method
System.out.println("delete status:" + fo.get());
// retrieve and check the value from cache
System.out.println("tutorialspoint value in cache - " + mcc.get("codingground"));
// Shutdowns the memcached client
mcc.shutdown();
}catch(Exception ex)
System.out.println(ex.getMessage());
}
}