错误信息如下:
The type 'ConnectionMultiplexer' exists in both 'StackExchange.Redis.StrongName, Version=1.2.6.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46' and 'StackExchange.Redis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46'
请问如何解决?
问题的原因:同一个 VS 解决方案项目中
解决方法:将项目 B 中 PackageReference 由 StackExchange.Redis 改为 StackExchange.Redis.StrongName
<ItemGroup>
<PackageReference Include="StackExchange.Redis.StrongName" Version="1.2.6" />
</ItemGroup>
dudu,你好
这样是能解决报名冲突的问题。但是statckexchange.redis这个包的版本就不能同步更新上去了。
现在用这个redis库遇到了timeout的问题。
StackExchange.Redis.RedisTimeoutException: Timeout performing GET AppUser_Driver_iOS_App_13814725839, inst: 1, queue: 3, qu: 0, qs: 3, qc: 0, wr: 0, wq: 0, in: 287, ar: 0, clientName: 172_17_16_7, serverEndpoint: 127.0.0.1:6379, keyHashSlot: 13597 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)
at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImplT in C:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 2101
at StackExchange.Redis.RedisBase.ExecuteSyncT in C:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line 81
at StackExchange.Redis.RedisDatabase.StringGet(RedisKey key, CommandFlags flags) in C:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisDatabase.cs:line 1647
而项目对redis的访问,是采用的单例模式,写了一个redishelper类
private static IDatabase _database;
private static IDatabase GetDatabase(int db = -1)
{
if (_database == null)
{
lock (_lockObj)
{
_database = RedisInstance().GetDatabase(db);
}
return _database;
}
else
{
return _database;
}
}
/// <summary>
/// 根据key返回T类型对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key">redis key</param>
/// <returns></returns>
public static T GetRedisValue<T>(string key)
{
var value = GetDatabase().StringGet(key);
if (string.IsNullOrEmpty(value))
{
return default(T);
}
return JsonConvert.DeserializeObject<T>(value);
}
但是,StackExchange.Redis.Extensions 没有 StrongName 版的,它们引用的还是 StackExchange.Redis 。https://github.com/imperugo/StackExchange.Redis.Extensions