扫码一下
查看教程更方便
Memcached delete 命令用于从 Memcached 服务器中删除现有的 key。
Memcached delete命令的基本语法如下所示
delete key [noreply]
delete 命令可能会产生以下结果之
在本例中,我们使用 jiyik 作为key,并设置其值为 memcached ,过期时间为900 秒。然后,会删除存储的key。
set jiyik 0 900 9
memcached
STORED
get jiyik
VALUE jiyik 0 9
memcached
END
delete jiyik
DELETED
get jiyik
END
delete jiyik
NOT_FOUND
要从 Memcached 服务器中删除数据,需要使用 Memcached delete 方法
import net.spy.memcached.MemcachedClient;
public class MemcachedJava {
public static void main(String[] args) {
// 连接 Memcached 服务
MemcachedClient mcc = new MemcachedClient(new
InetSocketAddress("127.0.0.1", 11211));
System.out.println("Connection to server successful");
System.out.println("set status:"+mcc.set("tutorialspoint", 900, "memcached").done);
// 从缓存获取数据
System.out.println("Get from Cache:"+mcc.get("tutorialspoint"));
// 删除
System.out.println("Delete from Cache:"+mcc.delete("tutorialspoint").isDone());
// 检测是否存在
System.out.println("Get from Cache:"+mcc.get("tutorialspoint"));
}
}
在编译和执行程序时,输出以下结果:
Connection to server successful
set status:true
Get from Cache:memcached
Delete from Cache:true
Get from Cache:null