Redis OSS Cluster spreads keys across multiple master shards, so running FLUSHALL on a single node only clears that shard. To remove all keys across the cluster, you must connect to every master shard or use a cluster-aware client that fans out the command. This guide introduces Cluster concepts and key commands, lists Prerequisites and safety requirements, provides Step-by-step CLI instructions to discover masters and flush them, shows Cluster-aware client automation with common libraries, outlines Performance best practices for large datasets and safe batch deletes, and ends with Troubleshooting for common pitfalls.
Prerequisites
Access to the Redis cluster with
redis-clior a cluster-aware client library.Authentication credentials with permission to run dangerous commands like
FLUSHALL.Awareness that
FLUSHALLis destructive and cannot be undone.
Step-by-Step Instructions
1. Discover all master shards
Run the following command on any cluster endpoint:
redis-cli -c -h <cluster-host> -p <cluster-port> CLUSTER SLOTS
This lists the hash slot ranges and the corresponding master shard IPs and ports.
2. Flush each master shard
For each master node returned from CLUSTER SLOTS, run:
redis-cli -h <shard-ip> -p <shard-port> FLUSHALL
Repeat for all master shards.
-
Include authentication if needed:
redis-cli -h <shard-ip> -p <shard-port> -a <password> FLUSHALL
3. Use a cluster-aware client library
Cluster-aware clients (redis-py, Jedis, go-redis, etc.) can issue FLUSHALL across all master nodes automatically.
Python example (redis-py):
from redis.cluster import RedisCluster
startup_nodes = [
{"host": "127.0.0.1", "port": 7000},
{"host": "127.0.0.1", "port": 7001},
{"host": "127.0.0.1", "port": 7002}
]
rc = RedisCluster(startup_nodes=startup_nodes, decode_responses=True)
rc.flushall()Best Practices for Performance
Schedule carefully:
FLUSHALLis blocking and may impact performance. Run during off-peak hours in production.Delete subsets safely: For selective deletion (e.g.,
user:*), useSCANwithUNLINKin batches, or Redis Insight bulk deletion, instead of blocking commands.Large clusters: For huge datasets (tens of millions of keys), pipelined
UNLINKwith batching reduces blocking and fragmentation. See bulk key deletion best practices.
Troubleshooting Common Issues
| Problem | Cause | Solution |
|---|---|---|
| Keys remain after flush | Only one shard was flushed | Run CLUSTER SLOTS and flush each master. |
redis-cli --cluster call FLUSHALL fails |
Not supported in all environments | Connect directly to each master shard and run FLUSHALL. |
| Permission denied | ACL restrictions | Ensure your user is permitted to run dangerous commands like FLUSHALL. |
Batch deletes fail with CROSSSLOT errors |
Multi-key deletes span shards in OSS Cluster | Use SCAN + UNLINK, pipelined per shard. |
Summary Table: Typical CLI Flow for Cluster Flush
| Step | Command Example | Notes |
|---|---|---|
| List master nodes | redis-cli -c -h <cluster-host> -p <port> CLUSTER SLOTS |
Identifies all master shard IPs and ports. |
| Flush each master | redis-cli -h <shard-ip> -p <shard-port> FLUSHALL |
Run for all masters; include -a <password> if needed. |
| Programmatic flush | (redis-py, Jedis, go-redis) | Automates FLUSHALL across all shards. |
0 comments
Please sign in to leave a comment.