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

Error: redis cluster flushall not working

What's Causing This Error

The 'redis cluster flushall' error usually occurs due to the fact that the FLUSHALL command is not allowed in a Redis Cluster by default. The Redis Cluster commands do not include commands that involve multiple keys located potentially on different nodes, as they are in conflict with its distributed nature. Consequently, these commands need to be issued separately for each node in the cluster.

Moreover, another possible cause might be the use of an outdated Redis client that does not support Redis Cluster commands. In this case, even if you're running a modern Redis server, the older client may be unable to perform certain operations, including 'flushall'.

Solution - Here's How To Resolve It

Firstly, if your client allows it, you can issue 'FLUSHALL' command to each node individually. This operation might require manual work or scripting based on your setup.

Here's an example using redis-cli:

for node in `redis-cli --cluster nodes 127.0.0.1:7000 | grep master | awk '{print $2}'`; do redis-cli -h ${node%:*} -p ${node##*:} flushall; done

In the script above, we first get the list of all master nodes in the cluster, then run 'flushall' for each of them.

Secondly, if you're dealing with an outdated client, consider updating your Redis client to a version that is compatible with your Redis server and supports Redis Cluster commands. Before doing so, ensure that the updated client is compatible with your application's current environment.

Lastly, while FLUSHALL can be handy during development, it's not recommended for production environments, as it can lead to data loss. Therefore, you should use it with caution.

Was this content helpful?

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