0 votes
in MemCached by

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 madanswer 0 900 9
memcached
STORED
get madanswer 
VALUE madanswer 0 9
memcached
END
flush_all
OK
get madanswer

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<span style="color:#666600

Related questions

0 votes
asked Jun 9, 2020 in MemCached by DavidAnderson
0 votes
asked Jun 9, 2020 in MemCached by DavidAnderson
...