- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在 .net core 2.0 中构建 web api 并将其部署在 kubernetes 上。我想将 IDistributedCache(带有 redis)与哨兵和主/从配置一起使用。我找不到任何相关文件。它如何处理主/从场景(故障转移情况)?
最佳答案
查看源代码应该会告诉您需要知道的一切: https://github.com/aspnet/Caching/blob/dev/src/Microsoft.Extensions.Caching.Redis/RedisCache.cs
如果您使用的是 nuget 扩展,则 IDistributedCache 实例应该是 RedisCache 类型。你应该能够施放它:
public RedisWrapperClassConstructor(IDistributedCache c)
{
cche = c as RedisCache;
//since pub/sub is only supported by Redis, we need to force the issue
if (cche == null) throw new InvalidCastException("distributed cache must be of type RedisCache");
EnsureTheConnectionMultiplexerIsSet();
}
有一个活跃的请求让扩展将多路复用器公开为依赖注入(inject)服务: https://github.com/aspnet/Caching/issues/343
现在你必须使用丑陋的反射:
private void EnsureTheConnectionMultiplexerIsSet()
{
if (_connection != null) return;
cche.Get("startup"); //populate the connection with a dummy request
var _connectionMultiplexorFieldInfo = typeof(RedisCache).GetField(nameof(_connection), BindingFlags.NonPublic | BindingFlags.Instance);
var vl = _connectionMultiplexorFieldInfo.GetValue(cche);
if (vl != null)
{
_connection = (ConnectionMultiplexer)vl;
if (_connection == null) throw new InvalidCastException("Could not cast the ConnectionMultiplexer");
}
if (_connection == null) throw new InvalidCastException("Could not access the ConnectionMultiplexer");
}
最重要的部分是异常。如果您更新您的 nuget 包并且底层类更改了它的字段名称,那么您将想要抛出该异常。多路复用器应该在整个应用程序中共享,因此这是一个非常罕见的情况,您可能需要进行一些反射(reflection)。
编辑:我忘了提到如何做哨兵的事情: https://github.com/StackExchange/StackExchange.Redis/pull/406
edit2:反射的需求现在已经解决了,有了更新的版本
关于c# - .net core IDistributedCache redis sentinel 支持master/slave,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49403973/
IDistributedCache作为标准 API 提供,用于从 ASP.NET 应用程序中访问分布式缓存。提供的 API 非常简单,基本上将缓存呈现为键值对的容器,DistributedCacheE
我正在使用 services.AddDistributedMemoryCache()在我的 .Net Core 3 Web API 中 startup.cs类(class)。当我第一次设置缓存时: p
我有一个 asp.net core 项目,我正在尝试使用 IDistributedCache (Redis)。 我想在自定义类中访问 IDistributedCache,而不仅仅是在 Controll
我将用户生成的一些 key 存储在 IDistributedCache 设置中。 key 是长期存在的,如果用户知道它们中的每一个,它们可以由用户手动撤销: public void Configure
我正在使用 .NET Core 2.0 和 Microsoft.Extensions.Caching.Redis 2.0。为什么 IDistributedCache.SetStringAsync 实际
我有一个基于asp.net core 2.1解决方案使用redis分布式缓存的项目。有些东西我还不明白。 我有一个类 myClassName,它的构造函数需要注入(inject)。 public cl
我有一个 Azure Redis 和 .Net Core 2 的工作实现,使用的代码与此 article 中描述的非常相似 我的问题是,如何从单元测试类实例化缓存实例?我查看了许多资源,但一无所获。
.Net Core 为两个接口(interface)( MemoryCache 和 DistributedMemoryCache )提供内存实现,但假设我们有一个可用的 IDistributedCac
我在 ASP.Net Core 2.2 API 中将 IDistributedCache 与 SQL Server 结合使用。 我注意到过期的记录仍然保留在表中。有没有办法删除缓存表中过期的记录? 最
希望我能得到一些关于哪种缓存机制最适合 Azure 的说明。 目前我的应用程序使用内存中 (IMemoryCache) 来保存经常访问的数据。 此功能是否与在单个 Web 服务器上一样?即存储在内存中
为了实现多个 IDistributedCache 定义,我有以下解决方案: public interface IDBCache : IDistributedCache { } public class
我正在 .net core 2.0 中构建 web api 并将其部署在 kubernetes 上。我想将 IDistributedCache(带有 redis)与哨兵和主/从配置一起使用。我找不到任
我需要使用 IDistributedCache在我的应用程序中,它可能是 MemoryDistributedCache或 RedisCache作为底层实现。我的理解是这些不是线程安全的,所以我创建了自
我正在使用带有 aws redis 缓存的 .net core api (2.1)。我没有看到将到期时间设置为 IDistributedCache.SetAsync 的方法.这怎么可能? 我的代码段如
我有一个 ASP.NET Core2 应用程序。我同时使用内置和 Autofac IoC 容器。我正在 Startup.cs 文件中设置所有组件注册。在执行此操作时,我还设置了我的 DBContext
我想在 ASP.NET Core 项目中实现分布式缓存(Redis)。经过一番研究后,我发现有两种方法可以使用 Startup.cs 和 ConnectionMultiplexer 中的 AddSta
我正在尝试在 MVC 6 中使用 Redis 缓存,但我无法构建我的项目。 我遵循了 https://github.com/aspnet/Caching/tree/dev/samples 中的示例-
我是一名优秀的程序员,十分优秀!