如何使用.net6操作redis?

How to use .net6 to operate redis?

我升级到最新的.net6版本,但是怎么配置连接服务,我找不到入口。我还能在 .net6 中使用之前的 Startup.cs 配置吗?非常感谢任何帮助!我已经阅读了文档,但对我没有帮助:https://docs.microsoft.com/en-us/dotnet/core/compatibility/6.0

1。您可以像下面这样注册 redis 服务。

builder.Services.AddStackExchangeRedisCache(options =>
{
    options.Configuration = "jason******FebB5A=,ssl=True,abortConnect=False";
});

并且您可以在您的控制器中使用 redis,如下所示:

public HomeController(ILogger<WeatherForecastController> logger, CosmosClient client,IDistributedCache distributedCache)
{
    _logger = logger;
    _client = client;
    _distributedCache = distributedCache;
}

测试结果如下: