Question: How to clear Memcached data?
Answer
To clear Memcached data, you can either delete individual keys or flush all keys. Here's how to do it:
Deleting individual keys
You can delete a single key from Memcached using the delete
command. The syntax for the command is as follows:
delete <key> [time]
<key>
- The name of the key you want to delete[time]
- An optional expiration time for the key. If you specify an expiration time, the key will be deleted after that many seconds.
Here's an example of deleting a key named my_key
:
$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
delete my_key
DELETED
Flushing all keys
If you want to clear all keys from Memcached, you can use the flush_all
command. This command will remove all keys from the cache. The syntax for the command is as follows:
flush_all [time]
[time]
- An optional expiration time for all keys. If you specify an expiration time, all keys will be deleted after that many seconds.
Here's an example of flushing all keys:
$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
flush_all
OK
Note that flushing all keys will remove all items from the cache, so use it with caution.
Was this content helpful?
Help us improve by giving us your feedback.
Other Common Memcached Questions (and Answers)
- Does Memcached expire?
- Does Memcached write to disk?
- What is the location of Memcached error log?
- How does Memcached consistent hashing work?
- Does restarting Memcached clear cache?
- Does Memcached support encryption?
- How to pronounce Memcached?
- How to check Memcached version in Linux?
- How to install Memcached in CentOS 7?
- How is Memcached implemented?
- How does Memcached work in PHP?
- How to install Memcached on Windows?
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Switch & save up to 80%
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost