Startup.cs中的代码如下:
var redisSection = Configuration.GetSection("redis"); var conf = redisSection.GetValue<string>("Configuration"); var redis = ConnectionMultiplexer.Connect(conf); services.AddDataProtection().PersistKeysToRedis(redis, "DataProtection-Keys");
运行时却出现下面的错误:
System.Security.Cryptography.CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information. ---> System.TimeoutException: Timeout performing LRANGE DataProtection-Keys, inst: 1, queue: 15, qu: 0, qs: 15, qc: 0, wr: 0, wq: 0, in: 17361, ar: 0, clientName: (Please take a look at this article for some common client-side issues that can cause timeouts: https://github.com/StackExchange/StackExchange.Redis/tree/master/Docs/Timeouts.md) at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server) at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server) at StackExchange.Redis.RedisDatabase.ListRange(RedisKey key, Int64 start, Int64 stop, CommandFlags flags) at Microsoft.AspNetCore.DataProtection.RedisXmlRepository.<GetAllElementsCore>d__4.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Microsoft.AspNetCore.DataProtection.RedisXmlRepository.GetAllElements()
是 StackExchange.Redis 对 .NET Core 支持的一个bug,详见:asp.net core concurrency issues
后来没办法了,下载 csredis 改成 .netcore 版使用在项目中
https://github.com/2881099/csredis
并且我们项目中发现这个问题的时候,大概是10月份,statckexchage.redis 非常坑
代码很乱很难看,相比csredis就干净很多