.NET app.config 中的 Couchbase 多个存储桶 [英] Couchbase multiple buckets in .NET app.config
本文介绍了.NET app.config 中的 Couchbase 多个存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Couchbase .Net 手册说我可以这样配置我的客户端:
<add uri="http://192.168.0.2:8091/pools/default"/><add uri="http://192.168.0.3:8091/pools/default"/></servers></couchbase>
有什么办法可以在 app.config 中定义多个存储桶,然后在我的应用中在它们之间切换吗?
解决方案
根据John的建议,我采用了这样的配置:
<预><代码><配置><configSections><sectionGroup name="couchbase"><section name="bucket-1" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>...<section name="bucket-N" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/></sectionGroup></configSections>...<沙发床><bucket-1><servers bucket="bucket-1" bucketPassword="pass"><add uri="http://10.0.0.1:8091/pools/default"/><add uri="http://10.0.0.2:8091/pools/default"/></服务器></bucket-1></沙发底座>...</配置>然后在应用代码中你可以得到bucket的客户端:
var client = new CouchbaseClient((CouchbaseClientSection)ConfigurationManager.GetSection("couchbase/bucket-1"));
如果.Net couchbase 库的开发者能够实现读取这样的配置就好了.
Couchbase .Net manual says that I can configure my client in this way:
<couchbase><servers bucket="default" bucketPassword="">
<add uri="http://192.168.0.2:8091/pools/default"/>
<add uri="http://192.168.0.3:8091/pools/default"/>
</servers></couchbase>
Is there any way to define sevral buckets in app.config and then switch between them in my app?
解决方案
According to John's suggestion, I used such configuration:
<configuration>
<configSections>
<sectionGroup name="couchbase">
<section name="bucket-1" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
...
<section name="bucket-N" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
</sectionGroup>
</configSections>
...
<couchbase>
<bucket-1>
<servers bucket="bucket-1" bucketPassword="pass">
<add uri="http://10.0.0.1:8091/pools/default"/>
<add uri="http://10.0.0.2:8091/pools/default"/>
</servers>
</bucket-1>
</couchbase>
...
</configuration>
Then in app code you can get bucket's client:
var client = new CouchbaseClient((CouchbaseClientSection)ConfigurationManager.GetSection("couchbase/bucket-1"));
It would be nice, if developers of .Net couchbase library implement reading such configuration.
这篇关于.NET app.config 中的 Couchbase 多个存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文