連線到一個桶

以程式設計方式配置連線:

var config = new ClientConfiguration
        {
            Servers = new List<Uri> {
                new Uri("http://localhost:8091/pools")
            },
            BucketConfigs = new Dictionary<string, BucketConfiguration>
              {
                { "default", new BucketConfiguration
                {
                  BucketName = "default",
                  UseSsl = false,
                  Password = "",
                  DefaultOperationLifespan = 2000,
                  PoolConfiguration = new PoolConfiguration
                  {
                    MaxSize = 10,
                    MinSize = 5,
                    SendTimeout = 12000
                  }
                }}
              }
        };

var cluster = new Cluster(config);
var bucket = cluster.OpenBucket();

web.config / app.config 中配置連線:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="couchbaseClients">
            <section name="couchbase" type="Couchbase.Configuration.Client.Providers.CouchbaseClientSection, Couchbase.NetClient" />
        </sectionGroup>
    </configSections>
    <couchbaseClients>
        <couchbase useSsl="false">
            <servers>
                <add uri="http://localhost:8091/pools"></add>
            </servers>
            <buckets>
                <add name="default" useSsl="false" password="">
                    <connectionPool name="custom" maxSize="10" minSize="5" sendTimeout="12000" />
                </add>
            </buckets>
        </couchbase>
    </couchbaseClients>
</configuration>

使用配置部分:

var cluster = new Cluster("couchbaseClients/couchbase");
var bucket = cluster.OpenBucket();