Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete everything in node redis?

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); 
like image 732
Nelson Avatar asked Jun 16 '16 18:06

Nelson


People also ask

How do I delete everything on Redis?

Redis Commands There are two major commands to delete the keys present in Redis: FLUSHDB and FLUSHALL. We can use the Redis CLI to execute these commands. The FLUSHDB command deletes the keys in a database. And the FLUSHALL command deletes all keys in all databases.

How do I delete a database in Redis?

open your Redis cli and There two possible option that you could use: FLUSHDB - Delete all the keys of the currently selected DB. FLUSHALL - Delete all the keys of all the existing databases, not just the currently selected one.


2 Answers

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 }); 
like image 84
MikeJannino Avatar answered Sep 18 '22 08:09

MikeJannino


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.

like image 43
U-ways Avatar answered Sep 17 '22 08:09

U-ways