Question: How to Clear Redis Queue?


To clear a Redis queue, you can use the DEL command which deletes a key from the database. If you want to delete multiple keys, you can use the KEYS and DEL commands together. Here are two common methods for clearing a Redis queue:

Method 1: Using DEL Command

If you know the name of your queue (e.g., "my_queue"), you can issue the DEL command to remove it:

DEL my_queue

Method 2: Using KEYS and DEL Commands

This method is useful if you have multiple queues with a shared pattern in their names (e.g., "queue_*"). First, find all the keys matching the pattern using the KEYS command, and then use the DEL command to delete them.

In the Redis CLI, you can use a loop to achieve this:

redis-cli KEYS 'queue_*' | xargs redis-cli DEL

Note: Be cautious when using this method as it may unintentionally delete keys you don't intend to remove. Always verify that the pattern matches only the intended keys before executing the command.

Remember, both methods will delete the entire queue, meaning that the data stored within those keys will be lost. Make sure to backup any important data before executing these commands.

Was this content helpful?

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.