Memcached flush_all命令用于从Memcached服务器清除所有数据(即键值对)。意味着, 此命令会使所有现有的缓存项无效。它接受一个可选参数, 这意味着在经过N秒后会使所有项目失效。
flush_all不会暂停服务器, 因为它会立即返回。它根本不会释放或刷新内存, 只会导致所有项目过期。
句法:
flush_all [time] [noreply]
这里,
时间:这是一个可选参数。此参数设置清除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
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客户端:
使用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
评论前必须登录!
注册