Couchbase .net client 개발
-
Upload
jr-p -
Category
Technology
-
view
129 -
download
3
Transcript of Couchbase .net client 개발
Couchbase 개발Couchbase를 사용한 응용프로그램 개발 방법 개요
목차 목표 Client SDK 기본 조작 method 그 외 method 질의 응답
목표 Couchbase 를 DB 로 사용하여 클라이언트 응용프로그램을 개발하기 위한 환경에 대한 이해
기본적인 조작방법 숙지
참조 문서 및 출처 카우치베이스 사이트
http://www.couchbase.com/communities/all-client-libraries
http://www.couchbase.com/documentation
http://www.couchbase.com/presentations
CLIENT SDKClient SDK 의 종류와 특징 , 설치 및 사용방법
Client SDK 다운로드 아래 URL에서 개발하고자 하는 언어의 SDK를 다운로드 http://www.couchbase.com/communities/all-client-libraries
SDK 종류 및 특징
.NET Client SDK 1.3.0 .NET 3.5 와 4.0 용 어셈블리 제공의존하는 어셈블리에 의해 Client Profile 은 비권장 됨 Visual Studio 의 Nuget 플러그인 사용시 아래 명령으로 설치 가능
Install-Package CouchbaseNetClient
Github 에서 소스코드 다운로드 가능 git clone
https://github.com/couchbase/couchbase-net-client.git
출처 : http://docs.couchbase.com/couchbase-sdk-net-1.3/
.NET Client SDK 1.3.0 어셈블리 파일 내용
카우치베이스 라이브러리 본체 Couchbase.dll
Memcached 라이브러리 Enyim.Caching.dll 로그 어댑터
Enyim.Caching.Log4NetAdapter.dll Enyim.Caching.NLogAdapter.dll
기타 utility 라이브러리 Newtonsoft.Json.dll : JSON 문자열 파싱 / 생성 NLog.dll, log4net.dll : 로그 생성 및 기록
기본 조작 method
DB 연결
조회 / 조작 (CRUD)
카운터
DB 연결 app|web.config 를 사용한 DB 연결 설정<?xml version="1.0"?> <configuration> <configSections> <section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/> </configSections> <couchbase> <servers bucket="default" bucketPassword=""> <add uri="http://192.168.0.2:8091/pools"/> <add uri="http://192.168.0.3:8091/pools"/> </servers> </couchbase> </configuration>
DB 연결 싱글톤 패턴으로 Client 객체 생성
public static class CouchbaseManager { private readonly static CouchbaseClient _instance;
static CouchbaseManager() { _instance = new CouchbaseClient(); }
public static CouchbaseClient Instance { get { return _instance; }
} }
DB 연결 DB 연결 코드 작성 예 1 : Bucket 목록 조회
//app.config 의 url 을 추출 var ClusterNodeList = ( (CouchbaseClientSection)System.Configuration.ConfigurationManager.GetSection("couchbase") ).Servers.Urls.ToUriCollection(); // 관리자 계정으로 bucket 목록 조회 var config = new CouchbaseClientConfiguration() { Username = Username, Password = Password }; foreach (var uri in ClusterNodeList) config.Urls.Add(uri); var buckets = new CouchbaseCluster(config).ListBuckets();
DB 연결 DB 연결 코드 작성 예 2 : 코드로 연결
config = new CouchbaseClientConfiguration() { Bucket = BucketName, BucketPassword = BucketPassword }; foreach (var uri in ClusterNodeList) config.Urls.Add(uri);
ClientInstance = new CouchbaseClient(config);
조회 / 조작 Store Methods
bool ClientInstance.Store(StoreMode, key, value)
반환값 : 성공시 true
bool Remove(string key)
public enum StoreMode { Add = 1, Replace = 2, Set = 3, }
조회 / 조작 ExecuteStore Methods
IStoreOperationResult ClientInstance. ExecuteStore(StoreMode, key, value)
var result = client.ExecuteStore(StoreMode.Add, "beer", new Beer()); if (!result.Success) { Console.WriteLine("Store failed with message {0}
and status code {1}", result.Message, result.StatusCode);
if (result.Exception != null) throw result.Exception; }
조회 / 조작 Get Methods
object ClientInstance.Get(key) T ClientInstance.Get<T>(key) IDictionary<string, object>
Get(IEnumerable<string> keys) var dict = client.Get(new string[] { "brewery", "beer" }); Console.WriteLine(dict["brewery"]); Console.WriteLine(dict["beer"]);
조회 / 조작 Get Methods
CasResult<object> GetWithCas(string key)
bool KeyExists(string key)
public struct CasResult<T> { public ulong Cas { get; set; } public T Result { get; set; } public int StatusCode { get; set; } }
카운터 Counter
ulong Increment(string key, ulong de-faultValue, ulong delta)
ulong Decrement(string key, ulong de-faultValue, ulong delta)
client.Remove("inventory"); //reset the counter client.Increment("inventory", 100, 1); //counter will be 100 client.Increment("inventory", 100, 1); //counter will be 101
그 외 method 비 JSON 문자열 조작
Append/Prepend 메소드 CAS 를 이용한 조작
Cas 메소드 ICasOperationResult
Lock 을 이용한 조작 GetWithLock/Unlock 메소드
그 외 method View 사용
GetView 메소드 Expiration
Touch 메소드 TimeSpan validFor( 초단위 )/DateTime expiresAt
Durability enum PersistTo enum ReplicateTo
질의 응답
감사합니다