Memcached Basics
Memcached Storage Commands
Memcached Retrieval Commands
Memcached Statistics Commands
Memcached Useful Resources
Selected Reading
Memcached Storage Commands
- Memcached - CAS
- Memcached - Prepend Data
- Memcached - Append Data
- Memcached - Replace Data
- Memcached - Add Data
- Memcached - Set Data
Memcached Retrieval Commands
- Memcached - Incr/Decr
- Memcached - Delete Data
- Memcached - Delete Key
- Memcached - Get CAS Data
- Memcached - Get Data
Memcached Statistics Commands
- Memcached - Clear Data
- Memcached - Stats sizes
- Memcached - Stats Slabs
- Memcached - Stats Items
- Memcached - Stats
Memcached Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Memcached - Clear Data
Memcached - Clear Data
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 Apppcation
To clear data from a Memcached server, you need to use the Memcached flush method.
Example
import net.spy.memcached.MemcachedCpent; pubpc class MemcachedJava { pubpc static void main(String[] args) { // Connecting to Memcached server on localhost MemcachedCpent mcc = new MemcachedCpent(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 compipng 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:trueAdvertisements