由于项目需要,准备上手nosql数据库,比对了一番之后终于决定使用 couchbase。好了开始吧:

安装

地址:http://www.couchbase.com/get-started-developing-nosql#Download_Couchbase_Server

版本:企业版4.5.1、社区版4.1.0

系统:windows、mac osx

输入一堆的必填项目后开始下载。

Windows安装

    Couchbase 上手nosql for .netCouchbase 上手nosql for .net

配置

Couchbase 上手nosql for .net

Couchbase 上手nosql for .netCouchbase 上手nosql for .net

Couchbase 上手nosql for .netCouchbase 上手nosql for .net

没什么特别需要注意的next到底创建一个数据库密码长度要超过6位

安装完成看到控制界面

Couchbase 上手nosql for .net

.Net

添加nuget引用

Couchbase 上手nosql for .net

Couchbase 上手nosql for .net

代码配置

var config = new ClientConfiguration

{

Servers = new List<Uri>

{

new Uri("http://192.168.27.101:8091/pools")

, new Uri("http://192.168.27.102:8091/pools")

, new Uri("http://192.168.27.103:8091/pools") }

,

BucketConfigs = new Dictionary<string, BucketConfiguration>

{

{

"default",new BucketConfiguration{ BucketName = "distributed_cache", Password = "secret" }

}

}

};

var cluster = new Cluster(config);

数据处理

using (var bucket = Cluster.OpenBucket())

{

var document = new Document<dynamic>

{

Id = "Hello",

Content = new

{

Name = "Couchbase"

}

};

 

var upsert = bucket.Upsert(document);

if (upsert.Success)

{

var get = bucket.GetDocument<dynamic>(document.Id);

document = get.Document;

var msg = string.Format("{0} {1}!", document.Id, document.Content.Name);

Console.WriteLine(msg);

}

Console.Read();

}

相关文章: