- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在 .NET Core 2.2 中开发一些 web api
需求将我们带到了数据存储/缓存/集中在多个 redis 存储中的地步(为了简单起见,我们假设有 2 个 redis 服务器)。
那将是(例如)
到目前为止,数据保护似乎有效,并且按照 basic usage guide 中的建议使用连接多路复用器进行配置(之前添加为单例以供重用) .
StartUp.ConfigureServices相关部分
ConnectionMultiplexer cm = ConnectionMultiplexer.Connect("server1:6729");
services.AddSingleton<IConnectionMultiplexer>(cm);
services.AddDataProtection()
.SetApplicationName("myapp")
.PersitKeysToStackExchangeRedis(cm, "DataProtection-Keys");
key 按预期存储在服务器 1 的 redis 存储中。
现在我需要集成第二个存储。
ConnectionMultiplexer 可以用来连接两个服务器吗?
ConnectionMultiplexer cm = ConnectionMultiplexer.Connect("server1:6729;server2:6729"); //?
如何让正确的数据库指向正确的(第一台或第二台)服务器?
最佳答案
或者只是有一个 ConnectionMultiplexer
工厂的单例:
public class ConnectionFactory
{
private Lazy<ConnectionMultiplexer> _cnn1 { get; set; }
private Lazy<ConnectionMultiplexer> _cnn2 { get; set;}
public ConnectionFactory(string cnn1, string cnn2)
{
_cnn1 = new Lazy<UserQuery.ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(cnn1));
_cnn2 = new Lazy<UserQuery.ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(cnn2));
}
public ConnectionMultiplexer GetConnection1()
{
return _cnn1.Value;
}
public ConnectionMultiplexer GetConnection2()
{
return _cnn2.Value;
}
}
然后像这样注册:
var factory = new ConnectionFactory("server1:6379", "server2:6379");
services.AddSingleton(factory);
var cm1 = factory.GetConnection1();
var cm2 = factory.GetConnection2();
....
关于c# - .NET Core StackExchange.Redis ConnectionMultiplexer 设置多个 redis 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54767766/
Basic Usage StackExchange.Redis 的文档解释说 ConnectionMultiplexer 是长期存在的,预计会被重用。 但是当与服务器的连接断开时怎么办? Connec
我正在尝试建立一个项目来了解 azure redis 缓存。当我尝试调试时,我收到一条消息“未找到 ConnectionMultiplexer.cs”。我在我的机器中也找不到该文件。 我已经安装了 S
在我的缓存 AddItem 和 GetItem 方法中,我在继续之前检查到 redis 的连接是否存在,是 ConnectionMultiplexer.IsConnected昂贵的方法调用?还是我应该
using (ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("redisIP:6379,allowAdmin=tru
在 ConnectionMultiplexer 中处理套接字故障的正确方法是什么?我知道它会在后台静静地重试,但是有没有公认的规范方法来处理这种断开连接之间的时间?由于无论如何我都将其包装在我们自己的
使用 StackExchange.Redis 时创建多个 ConnectionMultiplexer 实例有什么好处吗?我们正在对 Azure Redis 缓存进行大量读/写调用,想知道单个 Conn
我有一个 6 节点的 Redis 集群,如您所料,有 3 个从节点和 3 个主节点。 从 Redis 服务器的角度来看,一切看起来都很笨拙,我可以在服务器上调用 cluster failover 或
我们在应用程序中使用 C1 Azure Redis 缓存。最近,我们在 GET 操作上遇到了大量超时。 According to this article ,可能的解决方案之一是实现 Connecti
我尝试通过 ConnectionMultiplexer.Connect("127.0.0.1"); 连接到我的 Redis 服务器实例,但是尽管没有服务器启动和运行,连接不会抛出错误也不会引发任何 C
我在我的 Windows 7 机器上成功安装了 Redis 服务器。快速动手,一切都按预期进行。(使用来自 https://github.com/MSOpenTech/redis 的 MSI 安装程序
我正在使用 StackExchange.Redis 与 3 个不同的 Redis 实例通信:1 个在同一子网上,2 个远程。这是我的配置代码: var configurationOptions = n
我正在使用出色的 StackExchange.Redis 库来实现 ObjectCache。在 ObjectCache 中实现的接口(interface)方法之一是 long GetCount(...
我已经使用 Redis 缓存了我的数据库。当我在 redis 的 connectionmultiplexer 类的实例上运行 dispose() 方法时,它不会刷新键和数据库。 --- privat
我正在将 ConnectionMultiplexer 静态对象存储在 ASP.NET MVC 网站中,速度达到 ~500req/sec,这会触发 RedisLabs 上的 Redis 实例。偶尔我会看
我正在努力模拟与 StackExchange.Redis 库相关的行为,但无法弄清楚如何正确模拟它使用的密封类。一个具体的例子是在我的调用代码中我正在做这样的事情: var cachable
我正在 .NET Core 2.2 中开发一些 web api 需求将我们带到了数据存储/缓存/集中在多个 redis 存储中的地步(为了简单起见,我们假设有 2 个 redis 服务器)。 那将是(
我有一个使用 .aspx 页面用 VBS 编写的 azure web 应用程序。我需要这些页面来使用 StackExchange.Redis 访问我的 Azure 托管的 Redis 缓存。 如何跨多
我读到为了连接到 Azure Redis 缓存最好遵循这种做法: private static ConnectionMultiplexer Connection { get { return Lazy
如何使用 StackExchange.Redis ConnectionMultiplexer 而不是 BookSleeve ConnectionUtils 连接到 Redis sentinel。 我目
目前 SignalR.Redis 正在使用 Booksleeve。 但是,SignalR.Redis 现在已经迁移到 StackExchange.Redis,而不是 signalR.Redis(2.2
我是一名优秀的程序员,十分优秀!