Dragonfly Cloud is now available on the AWS Marketplace - Learn More

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?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

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