- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
using (ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("redisIP:6379,allowAdmin=true"))
{
Model.SessionInstances = connection.GetEndPoints()
.Select(endpoint =>
{
var status = new Status();
var server = connection.GetServer(endpoint); // Exception thrown here!
status.IsOnline = server.IsConnected;
return status;
});
}
以上代码运行在 ASP.NET ASPX 页面的代码后面。我在运行良好的命令行程序中运行了非常相似的代码,所以我不确定我在这里做错了什么。唯一的区别是代码使用的是 foreach
循环而不是 lambda。
每次运行这段代码时,我都会得到一个异常The specified endpoint is not defined
我发现这很奇怪,因为我从同一个连接获取端点。返回的端点是正确的。
我在这里做错了什么?
我确实意识到我不应该在每次加载页面时都打开一个新连接,但这只是我不经常访问的管理页面;所以我不担心性能开销。此外,我保存的连接隐藏在 CacheClass 中,该 CacheClass 抽象出特定的提供者。
最佳答案
您遇到此错误是因为您的 lambda 表达式返回的可枚举正在被惰性计算。当您的 lambda 表达式运行时,您的连接已被 using
语句关闭。
在 using
语句中,你应该执行你的 lambda 表达式,例如通过在末尾添加 .ToList()
:
using (ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("redisIP:6379,allowAdmin=true"))
{
Model.SessionInstances = connection.GetEndPoints()
.Select(endpoint =>
{
var status = new Status();
var server = connection.GetServer(endpoint);
status.IsOnline = server.IsConnected;
return status;
}).ToList();
}
关于c# - StackExchange.ConnectionMultiplexer.GetServer 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46917437/
我必须使用 getservbyname() 函数获取有关服务的信息,我已经检查过 _PATH_SERVICES 引用了服务数据库文件的“/etc/services”,但是当我尝试打印返回的信息端口号时
我正在尝试获取 MinecraftForge 中的 MinecraftServer 实例。 这是我一直在尝试的代码: MinecraftServer minecraftServer = Minecra
using (ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("redisIP:6379,allowAdmin=tru
来自 mongoDB.Driver 文档 (http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-csharp-driver/
这是我的数据库连接字符串: private static string ConnectionString = "mongodb://user:password@server:port/"; priva
什么时候应该调用 MongoClient.GetServer() 和 MongoServer.GetDatabase()? 之前,我在启动时创建了一个 MongoDatabase 实例,并将其用于所有
本文整理了Java中org.apache.hadoop.yarn.ipc.YarnRPC.getServer()方法的一些代码示例,展示了YarnRPC.getServer()的具体用法。这些代码示例
在Tomcat 7中等效于org.apache.catalina.ServerFactory.getServer()还是什么是检索org.apache.catalina.Session实例的最佳方法?
本文整理了Java中com.ucar.datalink.domain.media.parameter.zk.ZkMediaSrcParameter.getServers()方法的一些代码示例,展示了Z
我正在尝试熟悉从 C# 程序写入 MongoDB。我已经按照 http://mongodb.github.io/mongo-csharp-driver/1.11/getting_started/ 的建
我有这样的代码: // configure the SSLContext with a TrustManager SSLContext ctx = SSLContext.getInst
我是一名优秀的程序员,十分优秀!