我是 .NET C# 和 Cassandra 的新手,无法将它们相互连接。我搜索了很多,但没有找到关于它如何工作的明确解释。
我已经下载了 Cassandra,并使用 Python 2.7 安装了它,我可以运行服务器并且可以运行 cqlsh。然后我打开 Visual studio,创建一个新的 .NET Core 项目并安装 Cassandra C# 驱动程序包。
仅此而已,我不知道如何从 C# 到 Cassandra 创建表、键空间。
任何人都可以简单地解释一下如何创建一个简单的键空间、带有列的表来输出代码,以便我可以看到它是如何工作的?
最佳答案
它已有五年历史了,但我写了一篇关于如何使用 Cassandra 作为 ASP.NET MVC 项目后端的文章:http://www.aaronstechcenter.com/aspnet_mvc_cassandra.php
我的这篇文章的 Git 存储库也仍然存在:https://github.com/aploetz/ShipCrew
它的核心内容将在 CassandraDAO.cs 中:
private Cluster Connect() {
string user = getAppSetting("cassandraUser");
string pwd = getAppSetting("cassandraPassword");
string[] nodes = getAppSetting("cassandraNodes").Split(',');
QueryOptions queryOptions = new QueryOptions().SetConsistencyLevel(ConsistencyLevel.One);
Cluster cluster = Cluster.Builder()
.AddContactPoints(nodes)
.WithCredentials(user, pwd)
.WithQueryOptions(queryOptions)
.Build();
return cluster;
}
我确信驱动程序版本已经过时,但它应该足以让您开始使用。
关于c# - 如何连接 C# 和 Cassandra,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65071240/