C # use distributed cache Couchbase,

Source: Internet
Author: User
Tags couchbase couchdb

C # use distributed cache Couchbase,
I. Introduction

Currently, the most widely used Cache systems in the C # industry are Memcached and Redis. These two Cache systems can be said to be relatively mature solutions, but also the choice of many systems.

The Memcache Development Team developed Membase, which supports multiple Server Clusters, data slicing and replication, effectively improves service stability and data security, and supports persistent data storage. But the code is not stable enough. Later, the Membase team merged with the CouchDB team to launch a two-in-one product: Couchbase.

Couchbase has the following features:

1. Fully inherit from Memcache, and Native supports all Memcache operations;

2. inherits the features of Membase and supports cluster and data persistence;

3. inherits the document nature of CouchDB and supports data operations through views. The features of this View provide the convenience that memcache does not have in the past. However, compared with Mongodb, this View is simple and primitive, and is not a common requirement.

Today, I also learned how to use Couchbase easily.

2. Couchbase Server Installation

Server: http://www.couchbase.com/download select the appropriate version of your system to download and install. The latest 4.0.0.

After Couchbase is managed and installed on the web, you can see it in the browser. If not, you need to manually access http: // localhost: 8091/index.html. Localhost and IP address or hostname can be used for local installation.

On the displayed page, click SETUP, set by default, and click Next.

After installation, you can view the following information in the service:

Ii. Client call

Create a console application for testing and install the Couchbase client DLL through Nuget. My project is based on. NETFramework4.0, so select CouchbaseNetClient 1.3.12.

1 static void Main (string [] args) 2 {3 // configure Server 4 CouchbaseClientConfiguration cbcc = new CouchbaseClientConfiguration (); 5 // set various timeout periods 6 cbcc. socketPool. receiveTimeout = new TimeSpan (0, 0, 2); 7 cbcc. socketPool. connectionTimeout = new TimeSpan (0, 0, 4); 8 cbcc. socketPool. deadTimeout = new TimeSpan (0, 0, 10); 9 // use the default database 10 cbcc. urls. add (new Uri ("http: // 127.0.0.1: 8091/pools/default"); 11 12 // create a C Lient, configure the Client 13 CouchbaseClient client = new CouchbaseClient (cbcc); 14 // Add a data record 15 CasResult <bool> casResult = client. cas (StoreMode. add, "Test", "Hello World! "); 16 // Get the newly added data 17 Console. WriteLine (client. Get (" Test "); 18 Console. WriteLine (" complete! "); 19 Console. ReadLine (); 20}

StoreMode. Add, StoreMode. Replace and StoreMode. Set

Add: Add a new key;

Replace: update an existing key;

Set: indicates that if the key does not exist, it is added or updated if it exists.

Added (Cas), removed (Remove), and other methods are available in CouchbaseClient for further study.

 

The result of obtaining the set cache value from the first run is:

The following comments describe the Setting Value: CasResult <bool> casResult = client. Cas (StoreMode. Add, "Test", "Hello World! ");

The running value is still obtained:

Other test results:

The added data can also be seen in the WEB Background and encrypted:

 

Iii. Summary

It feels good to use it in a simple way. If you have time, continue the study. Here is a CouchBase installation configuration and instructions for use.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.