Delete All Keys in Redis

Delete All Keys in Redis

Redis is an in-memory data store widely used for caching, real-time analytics, and message brokering. Over time, you may need to delete all keys, whether for maintenance, testing, or clearing stale data. Redis provides efficient commands to wipe data either from a specific database or from all databases at once. This tutorial explains how to delete all keys in Redis.

1. All databases

To completely clear all keys from all databases in Redis, use FLUSHALL:

redis-cli FLUSHALL

This command removes all keys from every database, effectively resetting Redis.

2. Specific database

If you want to delete keys only from the specific database (e.g., database 0), use FLUSHDB:

redis-cli -n 0 FLUSHDB

By default, Redis has 16 databases (numbered from 0 to 15). Replace 0 with the desired database number if needed.

Leave a Comment

Cancel reply

Your email address will not be published.