首页 > 代码库 > Redis之清除所有缓存

Redis之清除所有缓存

方法:

/// <summary>
/// 清除redis所有缓存
/// </summary>
/// <param name="redisUrl"></param>
public static void RemoveAllRedisCache(string redisUrl)
{
    using (RedisClient redisClient = new RedisClient(redisUrl))

    using (var redisManager = new RedisManagerPool(redisUrl))
    {
        IRedisClient redis = redisManager.GetClient();
        List<string> list = redis.GetAllKeys();
        redis.RemoveAll(list);
    }
}

调用:

static void Main(string[] args)
{
    string RedisUrl = "3421@192.168.2.200:6379";
    RemoveAllRedisCache(RedisUrl);
    Console.WriteLine("清理成功");
    Console.ReadKey();
}

 

Redis之清除所有缓存