.NET Core 3 中的 Redis 缓存是否需要使用 Stack Exchange 包?

Does Redis Cache in .NET Core 3 requires the usage of the Stack Exchange package?

在 .NET Core 2.2 中,在我的 Startup.cs 中,我有以下内容:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDistributedRedisCache(...);             
}

但是现在,在.NET Core 3.0中,找不到AddDistributedRedisCache方法。在 docs 中,"Applies to" 部分显示仅支持 .NET Core 2.2

继 Microsoft 的 this tutorial 之后,他们在示例中使用了 services.AddStackExchangeRedisCache。这是否意味着我需要为 Redis 安装 Stack Exchange NuGet 包?为什么去掉了微软原生的Redis客户端方案?

要使用 AddDistributedRedisCache,您需要从 nuget 安装 Microsoft.Extensions.Caching.Redis。另一方面,如果您仔细检查 post 的文档,AdddistributedRedisCache use RedisCacheOptions and the ConfigurationOptions propertyStackExchange.Redis.ConfigurationOptions

通过他们的 git 回购协议进行了一些挖掘,但它已被删除。当前存储库中没有删除,https://github.com/aspnet/Extensions, but in the previous repository, that is now archived, https://github.com/aspnet/Caching

您可以在此线程中看到原始包的一些问题:https://github.com/aspnet/Caching/issues/410#issuecomment-418912525

移除发生在此处:https://github.com/aspnet/Caching/issues/423

我查看了 aspnet 中从 2.1 -> 2.2 和 2.2 -> 3.0 的重大更改列表,但没有列出任何内容。我将在文档中创建一个问题以查看它是否包含在内。

在这一点上,我认为答案是使用 StackExchange 版本。无论如何,它显然比旧软件包有了一些重大改进。

更新: 支持的最新包是 Microsoft.Extensions.Caching.StackExchangeRedis 简单地使用此包最适合 .NET Core 3.0 及更高版本。

类似于

services.AddStackExchangeRedisCache(action =>
                {
                    action.InstanceName = "WhatYouWantToNameIt";
                    action.Configuration = "127.0.0.1:6379";
                });

文档是 here!