memcached flush_all command is used to delete all data (key-value pairs) from the memcached server. it accepts an optional parameter called time that sets a time after which the memcached data is to be cleared.
syntax
the basic syntax of memcached flush_all command is as shown below −
flush_all [time] [noreply]
the above command always returns ok.
example
in the following example, we store some data into the memcached server and then clear all the data.
set tutorialspoint 0 900 9 memcached stored get tutorialspoint value tutorialspoint 0 9 memcached end flush_all ok get tutorialspoint end
clear data using java application
to clear data from a memcached server, you need to use the memcached flush method.
example
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());
}
}
output
on compiling and executing the program, you get to see the following output −
connection to server successfully set status:true get from cache:5 increment value:7 decrement value:6 get from cache:6 clear data:true