23

I am using StackExchange.Redis in my application to store key/values. I need to flush the entire db now which Redis is using. I found a way via command How do I delete everything in Redis? but how can I do this with StackExchange.Redis? I was not able to find any method for that?

I searched for Empty, RemoveAll etc on IDatabase object and found nothing.

1 Answer 1

36

The easiest way is to use FlushDatabase method or FlushDatabaseAsync from IServer

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost,allowAdmin=true");
var server = redis.GetServer("localhost");
server.FlushDatabase();
Sign up to request clarification or add additional context in comments.

6 Comments

Is there a way to do this via some command line tool? I'd hate to have to write code just to flush the cache during development...
sure, you can do this in via redis-cli.exe with the argument "flushall" to flush all data in redis or you can you "flushdb" just to flush the selected db. e.g. if you need to flush db 1 you the next commands - "select 1" to select db with index 1, "flushdb" to flush only selected db. please note, the default db index is 0
Is says "This operation is not available unless admin mode is enabled: FLUSHALL".
Make sure you set allowAdmin=true in the config string (or ConfigurationOptions).
The specified endpoint is not defined (Parameter 'endpoint')
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.