Couchbase概述

Couchbase概述

Couchbase概述

Couchbase概述
Couchbase最早叫Membase,是由Memcached項目組的一些頭目另立的山頭。
2011年與CouchDB合并,正式命名為Couchbase。
2013年,作為NoSQL技術初創企業,拿到了2500萬美元的D輪投資。
截稿時止,Couchbase最新的版本是4.1.0 Developer Preview。
吳劍 http://www.cnblogs.com/wu-jian
Couchbase是開源的,分布式NoSQL文檔型(或Key/Value型)內存數據庫,文檔結構基于大家都很熟悉的JSON。此外它內置了一個便捷的WEB管理后臺,提供企業版,社區版和源代碼的下載。如下是一些關于Couchbase介紹的文章:
Couchbase介紹,更好的Cache系統
NoSQL showdown: MongoDB vs. Couchbase
一些主要的官網入口:
官網主頁:http://www.couchbase.com
說明文檔:http://developer.couchbase.com/guides-and-references
下載地址:http://www.couchbase.com/nosql-databases/downloads
在安裝使用Couchbase前, 需要理解一些基礎名詞:
Node:節點,即一臺安裝了Couchbase的服務器,所有節點擁有相同的組件和服務,并提供相同的接口。
Cluster:集群,多個節點組成一個集群。
Bucket:Bucket類似于數據庫的概念,在Couchbase中我們可為不同邏輯的項目創建不同的Bucket。
Item:一個項即一個Key/Value鍵值對。
Couchbase服務端安裝
從官網下載服務端安裝包,然后按提示很簡單完成安裝過程.
安裝完成后會自動在瀏覽器中打開一個頁面,點擊“Setup”進行Couchbase服務端配置,官方的配置手冊可 參考這里
①設置節點的數據持久化存儲位置,建議將數據與索引使用不同位置
②設置節點的IP或主機名
③設置節點開啟的服務,以及內存分配
可選擇安裝Sample以方便學習,需要注意的是在Couchbase中,每個項目都是一個“Bucket”。如果不需要Sample,直接下一步就好。
①設置Bucket的類型,大多數情況下使用Couchbase即可
②為Bucket分配內存以及設置Cache Metadata,Cache Metadata的工作原理可 參考這里
③設置鏡像數量
④設置Bucket的I/O優先級,只有當Couchbase中存在多個Bucket時該值才具有實際意義
⑤是否允許Flush,不建議在生產環境中開啟
關于Bucket設置更詳細的說明可 參考這里
是否接收Couchbase版本更新通知,以及填寫注冊信息。
最后一步,設置管理員帳號與密碼。
Couchbase的安裝配置過程非常簡單,安裝成功后,會有一個“CouchbaseServer”的系統服務,當我們需要啟用或停用Couchbase時,通過對這個服務操作即可。
Couchbase客戶端配置(.Net)
在官網下載 .Net Client Library,然后在項目中添加引用:
app.config / web.config 配置示例:
?xml version="1.0" encoding="utf-8" ?><configuration> <!--Couchbase客戶端配置節點定義--> <configSections> <sectionGroup name="couchbaseClients"> <section name="couchbase" type="Couchbase.Configuration.Client.Providers.CouchbaseClientSection, Couchbase.NetClient" /> </sectionGroup> </configSections> <!--Couchbase客戶端配置,參考:http://developer.couchbase.com/documentation/server/4.1-dp/sdks/dotnet-2.2/configuring-the-client.html--> <couchbaseClients> <couchbase useSsl="false" operationLifespan="1000"> <servers> <add uri="http://127.0.0.1:8091/pools"></add> </servers> <buckets> <add name="default" useSsl="false" password="" operationLifespan="2000"> <connectionPool name="defaultPool" maxSize="10" minSize="5" sendTimeout="12000"></connectionPool> </add> </buckets> </couchbase> </couchbaseClients> <!--約束Newtonsoft.Json版本--> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
因為 Couchbase .net client library 使用了 Newtonsoft.json 6,有時我們的項目中使用了 Newtonsoft.json 的其它版本,比如我的項目中使用的就是7,所以需要在配置文件中添加一個 runtime 節點統一約束使用一個統一的版本,避免程序運行出錯。
Couchbase客戶端代碼示例
在安裝完成服務端和編寫客戶端代碼之前,其實還有一個很重要的環節:Couchbase服務端的管理,打開瀏覽器輸入 http://localhost:8091 即可進入管理界面,包括 Cluster、Node、Bucket、Item的管理,都是通過這個內置的WEB后臺進行的。管理后臺功能強大內容繁多,具體細節可 參考這里。
Couchbase的API非常靈活,包括客戶端的配置,與服務端的聯接,基礎的增刪讀寫操作,可以在代碼中精確控制每個細節。當然它也提供了一些封裝的Helper方便簡單調用。
官方提供了一個完整的.Net客戶端DEMO,可 點擊這里 下載。如果你需要深入研究 .Net Client SDK 可 點擊這里 下載它的源代碼。
如下代碼我封裝了一個Couchbase的增、刪、讀、寫示例:
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Couchbase;
using Couchbase.Core;
using Couchbase.Configuration.Client;
namespace ZhengHe.Cache.Couchbase { /// <summary> /// Couchbase工具 /// </summary> public static class Helper { /// <summary> /// 初始化 ClusterHelper /// 參考:http://developer.couchbase.com/documentation/server/4.1-dp/sdks/dotnet-2.2/cluster-helper.html /// </summary> static Helper() { //使用配置節點進行初始化 ClusterHelper.Initialize("couchbaseClients/couchbase"); } /// <summary> /// 在Bucket中獲取一個文檔 /// </summary> /// <typeparam name="T">動態數據類型</typeparam> /// <param name="key">文檔唯一標識</param> /// <param name="bucketName">指定Bucket名稱</param> /// <returns></returns> public static T DocumentGet<T>(string key, string bucketName = "default") {
var bucket = ClusterHelper.GetBucket(bucketName); var result = bucket.GetDocument<T>(key);
if (result.Success) {
return result.Content; }
return default(T); }
/// <summary> /// 在Bucket中添加/更新一個文檔
/// </summary> /// <typeparam name="T">動態數據類型, The actual document value to store. This can be a scalar value, an object, or a dynamic type.</typeparam> /// <param name="key">文檔唯一標識</param> /// <param name="content">動態數據</param> /// <param name="expiry">過期時間(秒),如果小于或等于0表示持久存在</param> /// <param name="bucketName">指定Bucket名稱</param> /// <returns></returns> public static bool DocumentUpsert<T>(string key, T content, int expiry = 0, string bucketName = "default") { if (expiry < 0) expiry = 0; var bucket = ClusterHelper.GetBucket(bucketName); var result = bucket.Upsert( new Document<T> { Id = key, Content = content, Expiry = (uint)(expiry * 1000) //將秒轉換為毫秒 }); if (result.Success) return true; return false; }
/// <summary> /// 在Bucket中刪除一個文檔
/// </summary> /// <param name="key">文檔唯一標識</param> /// <param name="bucketName">指定Bucket名稱</param> /// <returns></returns> public static bool DocumentRemove(string key, string bucketName = "default") {
var bucket = ClusterHelper.GetBucket(bucketName); var result = bucket.Remove(key);
if (result.Success)
return true;
return false; } }//end class}
結束語
關于緩存服務,在Memcached之前,自己嘗試過封裝.Net Cache,研究過MySQL Memory存儲引擎。因各種原因,Memcached被擱置了好久,直到最近幾天,把Couchbase的文檔通讀了一遍,完成了簡單的DEMO,不得不說,Couchbase作為一款成熟的商業運營的開源軟件,確實做的非常不錯,文檔和DEMO非常細致,開發部署異常簡潔。
寫完DEMO后,還迫不及待的進行了一番測試,結果在我的大部分應用中,效率能提升70%左右(當然,這些應用之前沒有部署Memcache技術),后面幾天我會盡快將Couchbase部署至生產環境。目前花的時間不多,對Couchbase的研究也僅限于初步了解,后續會繼續將心得體會和一些細節在此分享,不足之處也請大家指正。
原文地址:http://www.cnblogs.com/wu-jian/p/4957895.html
???企企csvcsvcsvcsvcsvcsv
posted on 2018-08-16 21:11 micwin 閱讀(...) 評論(...) ?編輯 收藏

轉載于:https://www.cnblogs.com/chinanetwind/articles/9490070.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/279594.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/279594.shtml
英文地址,請注明出處:http://en.pswp.cn/news/279594.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Windows 2012 - Dynamic Access Control 淺析

Windows 2012相對于前幾個版本而已&#xff0c;做出了大量的改進&#xff0c;尤其體現在安全性和虛擬化方面。Dynamic Access Control ( 動態訪問控制&#xff09;是微軟在文件服務器的訪問控制上的新功能&#xff0c;極大的提高了安全性和靈活性。經過一天的研究學習&#xff…

windows rt_如何在Windows RT上輕松將網站添加到Flash白名單

windows rtMicrosoft’s Surface RT and other Windows RT-based machines include the Flash browser plugin, but it only runs on websites Microsoft has whitelisted. We have covered how you can add any website to the Flash whitelist, but now there’s an easier w…

powershell實現設置程序相關性腳本

公司一直有臺服務器cpu占用很高&#xff0c;分析出是恒生監控程序java占用很高&#xff0c;且三個java程序&#xff0c;僅其中一個很高&#xff0c;要恒生解決&#xff0c;一直未解決&#xff0c;導致每周重啟&#xff0c;我司運維都要手動進行程序相關性設置&#xff0c;給運維…

解決npm 的 shasum check failed for錯誤

使用npm安裝一些包失敗&#xff0c;類似如下報錯情況&#xff1a; C:\Program Files\nodejs>npm update npm npm ERR! Windows_NT 10.0.14393 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\np…

chromebook刷機_您可以購買的最好的Chromebook,2017年版

chromebook刷機While once considered a novelty item by many tech enthusiasts, Chromebooks have broken out of the “just a browser” mold and become legitimate laptops. They’re full-featured, lightweight machines that can do everything most users need them …

Jmeter JDBC請求-----數據庫讀取數據進行參數化 通過SSH跳板機連接數據庫

前期準備&#xff1a; jdbc驅動&#xff1a;mysql-connector-java-5.1.7-bin.jar Jmeter 要鏈接MySQL數據庫&#xff0c;首選需要下載mysql jdbc驅動包&#xff08;注&#xff1a;驅動包的版本一定要與你數據庫的版本匹配&#xff0c;驅動版本低于mysql版本有可能會導致連接失敗…

Exchange server 2010 beta安裝部署流程

本文使用了微軟公開發布的exchange server 2010 beta進行部署測試。這篇文檔將用到下列產品 windows server 2008 64bit enterprise AD function at windows server 2008 exchange server 2010 beta ----------該exchange server 2010 beta版本屬于早期版本&#xff0c;目前最新…

08.15《CEP職業發展規劃課》

在12,13號的放假后&#xff0c;14,15號安排了CEP職業發展規劃課&#xff0c;為期兩天的課&#xff0c;內容也是很豐富。 在14號的早上&#xff0c;學習了職場中的基本禮儀、和基本素養的培訓&#xff0c;同時對未來的職業規劃做出了大致的分析。 在14號的下午開始了簡歷寫作的課…

usb 驅動修復_您可以修復物理損壞的USB驅動器嗎?

usb 驅動修復Sometimes accidents happen to a USB drive, and you find yourself in a very bad position when your only copy of an important document is on there. When something like this happens, is it possible to fix a physically broken USB drive? Today’s S…

大白話5分鐘帶你走進人工智能-第二十節邏輯回歸和Softmax多分類問題(5)

大白話5分鐘帶你走進人工智能-第二十節邏輯回歸和Softmax多分類問題(5) 上一節中&#xff0c;我們講解了邏輯回歸的優化&#xff0c;本節的話我們講解邏輯回歸做多分類問題以及傳統的多分類問題&#xff0c;我們用什么手段解決。 先看一個場景&#xff0c;假如我們現在的數據集…

Exchange 2016部署實施案例篇-01.架構設計篇(上)

年前就答應大家要給大家寫一個關于Exchange規劃部署的文章&#xff0c;一直忙到現在也沒有倒出時間來寫這個東西。特別是節后&#xff0c;更是開工不利啊&#xff0c;各種奇葩問題&#xff0c;真心無語了。廢話就不多說了&#xff0c;開始今天的議題。 相信各位對Microsoft Exc…

bzoj 4598: [Sdoi2016]模式字符串

題目描述 給出n個結點的樹結構T&#xff0c;其中每一個結點上有一個字符&#xff0c;這里我們所說的字符只考慮大寫字母A到Z&#xff0c;再給出長度為m的模式串s&#xff0c;其中每一位仍然是A到z的大寫字母。 Alice希望知道&#xff0c;有多少對結點<u&#xff0c;v>滿足…

[譯] 機器學習可以建模簡單的數學函數嗎?

原文地址&#xff1a;Can Machine Learning model simple Math functions?原文作者&#xff1a;Harsh Sahu譯文出自&#xff1a;掘金翻譯計劃本文永久鏈接&#xff1a;github.com/xitu/gold-m…譯者&#xff1a;Minghao23校對者&#xff1a;lsvih&#xff0c;zoomdong機器學習…

下載spotify音樂_如何在Spotify上播放更高質量的音樂

下載spotify音樂With Spotify Premium, you get access to higher quality music streaming. By default (and if you’re on the free plan), Spotify streams at 96kbps on mobile and 160kbps on your computer. At these sort of bitrates, you’ll hear a small but notic…

ubuntu scp命令或者用root連接ssh提示:Permission denied, please try again.錯誤

1、su -            #&#xff01;&#xff01;&#xff01; 2、vi /etc/ssh/sshd_config 3、PermitRootLogin yes    # 找到此字段&#xff0c;改為此行所示 4、/etc/init.d/ssh restart    # 重啟ssh服務 轉載于:https://www.cnblogs.com/weiyiming007/p…

Windows下壓縮包安裝Mysql

1. 下載mysql壓縮包 2. 解壓到指定目錄&#xff0c;例如D:\Program Files\mysql-5.7.25-winx64 3. 在目錄下創建配置文件my.ini [mysqld] port 3306 basedirD:/Program Files/mysql-5.7.25-winx64 datadirD:/Program Files/mysql-5.7.25-winx64/data max_connections200 char…

如何從終端打開Ubuntu Nautilus文件瀏覽器

Recently, we showed you how to open a directory in Terminal from within Nautilus. However, what if you’re working on the command line in Terminal and need to access the same directory in Nautilus? There’s an easy solution for that. 最近&#xff0c;我們向…

mysql 面試知識點筆記(七)RR如何避免幻讀及非阻塞讀、范式

2019獨角獸企業重金招聘Python工程師標準>>> 表象&#xff1a;快照讀&#xff08;非阻塞讀&#xff09;--偽MVCC &#xff08;Multi-Version Concurrent Controll多版本并發控制&#xff09; 內在&#xff1a;next-key鎖(record鎖gap鎖) rr serializabel 都支持gap鎖…

pdf 奇數頁插入頁碼_如何在Word 2013中的奇數頁碼上啟動新部分

pdf 奇數頁插入頁碼When working on a long document or a book in Word, it’s common to divide the document into sections or chapters. A common practice is to start each new section or chapter on an odd page. This is easily accomplished using sections in Word…

徹底攻克C語言指針

前面我們講解了指針數組、二維數組指針、函數指針等幾種較為復雜的指針&#xff0c;它們的定義形式分別是&#xff1a; int *p1[6]; //指針數組int *(p2[6]); //指針數組&#xff0c;和上面的形式等價int (*p3)[6]; //二維數組指針int (*p4)(int, int); //函數指針我相信大部分…