Dragonfly

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]
```

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]
```

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?

Other Common Memcached Questions (and Answers)

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