Remove/Delete all/one item from StackExchange.Redis cache

前端 未结 4 522
执念已碎
执念已碎 2021-01-31 14:54

I am using StackExchange.Redis client with Azure Redis Cache Service. Here is my class,

public class RedisCacheService : ICacheService
{
    private readonly ISe         


        
4条回答
  •  隐瞒了意图╮
    2021-01-31 15:17

    I could not able to flush database in Azure Redis Cache, got this error:

    This operation is not available unless admin mode is enabled: FLUSHDB

    Instead iterate through all keys to delete:

    var endpoints = connectionMultiplexer.GetEndPoints();
    var server = connectionMultiplexer.GetServer(endpoints.First());
    //FlushDatabase didn't work for me: got error admin mode not enabled error
    //server.FlushDatabase();
    var keys = server.Keys();
    foreach (var key in keys)
    {
      Console.WriteLine("Removing Key {0} from cache", key.ToString());
      _cache.KeyDelete(key);
    }
    

提交回复
热议问题