用C#代码设置Couchbase客户端bucket密码
在我的C#代码中,我想使用ctor版本创建Couchbase客户端,我可以传入bucketName和密码:用C#代码设置Couchbase客户端bucket密码,c#,couchbase,C#,Couchbase,在我的C#代码中,我想使用ctor版本创建Couchbase客户端,我可以传入bucketName和密码: // // Summary: // Initializes a new instance of the Couchbase.CouchbaseClient class using the // default configuration and the specified bucket. // // Remarks: // The configuration is
//
// Summary:
// Initializes a new instance of the Couchbase.CouchbaseClient class using the
// default configuration and the specified bucket.
//
// Remarks:
// The configuration is taken from the /configuration/Couchbase section.
public CouchbaseClient(string bucketName, string bucketPassword);
在我的web.config文件中,
部分如下所示:
<couchbase>
<servers bucket="beer-sample" bucketPassword="">
<add uri="localhost:8091/pools" />
</servers>
</couchbase>
上述行始终失败,错误为“找不到注释”。有人能帮忙吗 首先,您使用的是Couchbase.Net SDK的旧版本。 Couchbase客户端是使用Couchbase的旧方法 请参阅新指南-> 其次,必须使用您想要的密码创建bucket 例如:
var clientConfiguration = new ClientConfiguration();
clientConfiguration.Servers = new List<Uri> { new Uri("http://localhost:8091") };
Cluster Cluster = new Cluster(clientConfiguration);
using (var bucket = Cluster.OpenBucket("bucketpwd", "1234"))
{
Console.WriteLine("Bucket Opened");
}
var clientConfiguration=new clientConfiguration();
clientConfiguration.Servers=新列表{新Uri(“http://localhost:8091") };
集群=新集群(客户端配置);
使用(var bucket=Cluster.OpenBucket(“bucketpwd”、“1234”))
{
控制台写入线(“桶打开”);
}
希望有帮助。有关Couchbase Server 3.0/3.1的信息,请参阅本文档
ClientConfiguration example
var config = new ClientConfiguration
{
Servers = new List<Uri>
{
new Uri("http://192.168.56.101:8091/pools"),
new Uri("http://192.168.56.102:8091/pools"),
new Uri("http://192.168.56.103:8091/pools"),
new Uri("http://192.168.56.104:8091/pools"),
},
UseSsl = true,
DefaultOperationLifespan = 1000,
BucketConfigs = new Dictionary<string, BucketConfiguration>
{
{"default", new BucketConfiguration
{
BucketName = "default",
UseSsl = false,
Password = "",
DefaultOperationLifespan = 2000,
PoolConfiguration = new PoolConfiguration
{
MaxSize = 10,
MinSize = 5,
SendTimeout = 12000
}
}}
}
};
using (var cluster = new Cluster(config))
{
IBucket bucket = null;
try
{
bucket = cluster.OpenBucket();
//use the bucket here
}
finally
{
if (bucket != null)
{
cluster.CloseBucket(bucket);
}
}
}
}
ClientConfiguration示例
var config=newclientconfiguration
{
服务器=新列表
{
新Uri(“http://192.168.56.101:8091/pools"),
新Uri(“http://192.168.56.102:8091/pools"),
新Uri(“http://192.168.56.103:8091/pools"),
新Uri(“http://192.168.56.104:8091/pools"),
},
usesl=true,
默认操作寿命=1000,
BucketConfigs=新字典
{
{“默认”,新BucketConfiguration
{
BucketName=“默认值”,
usesl=false,
密码=”,
默认操作寿命=2000,
PoolConfiguration=新的PoolConfiguration
{
最大尺寸=10,
MinSize=5,
发送超时=12000
}
}}
}
};
使用(var集群=新集群(配置))
{
IBucket bucket=null;
尝试
{
bucket=cluster.OpenBucket();
//用这里的水桶
}
最后
{
if(bucket!=null)
{
集群。闭桶(桶);
}
}
}
}
这是一个有点老的话题,但也许它可以帮助有同样问题的人 我目前正在使用couchbase.net客户端2.7.5
var clusterConfig = new ClientConfiguration
{
Servers = new List<Uri>{new Uri("http://couchbase0-node.io:8091")},
PoolConfiguration = new PoolConfiguration()
};
using (var cluster = new Cluster(clusterConfig))
{
var authenticator = new PasswordAuthenticator(username, password);
cluster.Authenticate(authenticator);
using (var bucket = cluster.OpenBucket(bucketName))
{
// Do something like :
var data = await bucket.GetAsync<T>(cacheKey);
// Other staff
}
}
var clusterConfig=new ClientConfiguration
{
服务器=新列表{新Uri(“http://couchbase0-node.io:8091")},
PoolConfiguration=新的PoolConfiguration()
};
使用(var cluster=newcluster(clusterConfig))
{
var authenticator=新密码验证器(用户名、密码);
集群认证(authenticator);
使用(var bucket=cluster.OpenBucket(bucketName))
{
//做一些类似于:
var data=wait bucket.GetAsync(cacheKey);
//其他工作人员
}
}
有关更多信息,请参见:
var clusterConfig = new ClientConfiguration
{
Servers = new List<Uri>{new Uri("http://couchbase0-node.io:8091")},
PoolConfiguration = new PoolConfiguration()
};
using (var cluster = new Cluster(clusterConfig))
{
var authenticator = new PasswordAuthenticator(username, password);
cluster.Authenticate(authenticator);
using (var bucket = cluster.OpenBucket(bucketName))
{
// Do something like :
var data = await bucket.GetAsync<T>(cacheKey);
// Other staff
}
}