49

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); 
2
  • need a working sample code for this question. Tried the mentioned answers, but they are not working. Commented Oct 28, 2022 at 10:41
  • If you are using node-redis then you should use the redis built in function: client.FLUSHDB(); Commented Sep 21, 2023 at 12:47

2 Answers 2

89

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 }); 
Sign up to request clarification or add additional context in comments.

2 Comments

flushdb will flush keys from selected database, flushall - will flush keys from all databases.
how to specify db ?
18

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.