Memcached教程

Memcached flush_all

Memcached flush_all 命令用于从Memcached服务器清除所有数据(即键值对)。意味着,此命令会使所有现有的缓存项无效。它接受一个可选参数,这意味着在经过N秒后会使所有项目失效。
flush_all不会暂停服务器,因为它会立即返回。它根本不会释放或刷新内存,只会导致所有项目过期。

语法:

flush_all [time] [noreply]
在这里
time: 这是一个可选参数。此参数设置清除Memcached数据的时间。
noreply: 。它是可选参数。它用于通知服务器不发送任何答复。

返回值:

flush_all命令总是返回OK。

在Ubuntu中的示例:

set city 0 900 9
bangalore
STORED
get city
VALUE city 0 9
bangalore
END
flush_all
OK
get city
END
Memcached清除数据

Windows中的示例

我们来看一个示例,首先,我们将一些数据存储到Memcached服务器中,然后清除所有数据。
set city 0 900 9
bangalore
STORED
get city
VALUE city 0 9
bangalore
END
flush_all
OK
get city
END
Memcached服务器
Memcached清除数据
Memcached客户端:
Memcached清除数据

使用Java应用程序清除数据

为了从Memcached服务器清除数据,java提供了Memcached刷新方法。

示例:

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

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4