【发布时间】:2022-01-19 20:04:00
【问题描述】:
我在 .Net 6 上的 Redis 中有一个奇怪的错误。当我在这里运行测试代码时:
https://github.com/redis-developer/redis-graph-dotnet-basic-app/blob/main/Program.cs
它工作得很好。在这种情况下,代码在 program.cs 文件中运行。
当我将该代码移植到一个类时,以便更好地管理封装和复杂性。这是行不通的。它所做的是运行代码,当它到达:await graph.QueryAsync 部分时,它只是停止调试器。确实很奇怪。
这是我正在使用的代码。任何想法或建议:
//Program.cs (Relevant Bits)
using RedisTest //PROGRAM //WRITE TO REDIS ENTERPRISE CLOUD Process_LoadGraph process_LoadGraph = new Process_LoadGraph(); process_LoadGraph.Controller(results);
//SHARED CONNECTION CLASS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StackExchange.Redis;
namespace RedisTest
{
public class RedisSharedConnection
{
public static ConnectionMultiplexer Connection
{
get
{
return lazyConnection.Value;
}
}
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
ConnectionMultiplexer connectionMultiplexer = ConnectionMultiplexer.Connect(ConfigData.dbConnectionString);
return connectionMultiplexer;
});
}
}
//USAGE CLASS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NRedisGraph;
namespace RedisTest
{
public class Process_LoadGraph
{
public async void Controller(List<Result> results)
{
//Setup
var redisConnection = RedisSharedConnection.Connection;
//var redisConnection = ConnectionMultiplexer.Connect(ConfigData.dbConnectionString);
var db = redisConnection.GetDatabase(ConfigData.dbId);
var graph = new RedisGraph(db);
string graphName = ConfigData.graphName;
//Test Transaction
// Create Bob
// CRASHES HERE
var createBobResult = await graph.QueryAsync("pets", "MERGE(:human{name:'Bob',age:32})");
}
}
}
【问题讨论】:
-
添加更多上下文。你如何实例化你的类?
-
是的,类被实例化了。
-
但是怎么做呢?请出示您的
Program.cs。 -
请编辑此代码并将其添加到问题中。请同时添加您有什么样的错误/消息。
-
我已按要求进行了编辑。请注意没有错误消息,IDE 只是停止执行代码。
标签: c# .net redis stackexchange.redis