How to delete everything in node redis?

29,809

Solution 1

Perhaps flushdb or flushall are options that you can look into.

In Node, with the client, these look like this:

client.flushdb( function (err, succeeded) {
    console.log(succeeded); // will be true if successfull
});

Solution 2

Starting from Redis 4.0.0 or greater, you can now delete all keys asynchronously using FLUSHALL [ASYNC]. Using the client, just pass the 'ASYNC' option to the command like so:

client.flushall('ASYNC', callback);

Use FLUSHDB [ASYNC] to flush keys from a selected database. Use FLUSHALL [ASYNC] to flush keys from all databases.

Share:
29,809
Nelson
Author by

Nelson

Updated on July 09, 2022

Comments

  • Nelson
    Nelson almost 2 years

    I want to be able to delete all the keys. Is there a way to flush all in node redis?

    Redis client:

    client = redis.createClient(REDIS_PORT, REDIS_HOST);
    
  • Lukas Liesis
    Lukas Liesis over 6 years
    flushdb will flush keys from selected database, flushall - will flush keys from all databases.
  • MartianMartian
    MartianMartian about 2 years
    how to specify db ?