转载

Memcached删除/Delete数据

   

Memcached的delete命令用于删除memcached服务器现有的键。

语法

memcached delete命令的基本语法如下所示:

 delete key

如果键成功删除,则返回DELETED,如果key没有找到则返回NOT_FOUND,否则返回ERROR。

示例

 set yiibai 0 900 9 memcached STORED get yiibai VALUE yiibai 0 9 memcached END delete yiibai DELETED get yiibai END delete yiibai NOT_FOUND

在上面的例子中,我们已经使用yiibai作为键,并存储在memcached其900秒后失效,之后删除所存储的键。

使用Java应用程序删除数据

要从memcached服务器中删除数据,需要使用memcached的delete方法。

示例

 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("yiibai", 900, "memcached").done);       //Get value from cache       System.out.println("Get from Cache:"+mcc.get("yiibai"));       //delete value from cache       System.out.println("Delete from Cache:"+mcc.delete("yiibai").isDone());       //check whether value exists or not       System.out.println("Get from Cache:"+mcc.get("yiibai"));    } }

输出

当上述程序编译和运行,它提供了以下的输出:

 Connection to server successfully set status:true Get from Cache:memcached Delete from Cache:true Get from Cache:null
   
正文到此结束
Loading...