4

I am trying to delete a Redis Key. I am using the StackExchange.Redis library and have tried searching on StackOverflow for a way to delete a key. I found this link: StackExchange Redis delete all keys that start with

But my library does not have a method called Database.KeyDelete. How do I get that method?

public void DeleteCacheByKey(string Key)
{
    ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0..1:6379");
    var server = redis.GetServer("127.0.0..1:6379");
    redis.Database.KeyDelete(key);
}

1 Answer 1

3

Assuming you are using the default Redis DB, you should try like this :

public void DeleteCacheByKey(string Key)
{
    ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1:6379");
    redis.GetDatabase().KeyDelete(key);
}

Note that the ConnectionMultiplexer is IDisposable. It should be diposed.

Sign up to request clarification or add additional context in comments.

Comments

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.