First, Introduction
The Cache system most used by the C # industry today is mainly memcached and Redis. These two Cache systems can be said to be a more mature solution, but also a lot of system of course choice. Memcache is basically a standard for development, but for memcache clusters, many on-line deployments are still very thin. Several problems exist: not robust, data insecure, configuration changes can result in access anomalies, backing data consistency, Memcached does not support persistence.
In view of the above problems, Memcache's development team has developed membase, supporting multiple server clusters, slicing and replicating data, effectively improving service stability and data security, and supporting persistent storage of data. The stability of the code is not good enough, I used a part of the online business membase, and later because of a few inexplicable access operation slow, can only be withdrawn back to Memcache.
The Membase team then merged with the COUCHDB team to launch the two-in-product: Couchbase.
The biggest features of Couchbase:
1, fully inherit memcache, native support all memcache operation;
2, inherit the characteristics of Membase, support cluster and data persistence;
3, inherit the document nature of COUCHDB, support the operation of data through view. The feature of this view provides the convenience that Memcache previously did not have, but it is simple and primitive compared to MongoDB, it is not a function of universal demand.
Today, we also learn the simple use of couchbase.
Second, Couchbase service-side installation
Server: Http://www.couchbase.com/download Select the appropriate version of the system to download and install. Currently the latest 4.0.0.
Couchbase Web-based management, after installation, if successful, then you can see in the browser. If you do not have to do so manually access http://localhost:8091/index.html. This machine can be installed with localhost, can use IP or hostname.
On the page that opens, click Setup, default settings, then click Next, and then go to the following
Enter the administrator password. Proceed to next and finalize the configuration to enter the homepage. There are a lot of things to look at in there.
After installation, you can also check the service to see:
Second, the client calls
Create a console application for testing, and then use NuGet to couchbase the client's DLL installation. My project is based on. NETFramework4.0, so choose Couchbasenetclient 1.3.12.
The reference is complete, the default connection address is: Http://127.0.0.1:8091/pools/default, code code for a simple call:
1 Static voidMain (string[] args)2 {3 //Configure the server4Couchbaseclientconfiguration CBCC =Newcouchbaseclientconfiguration ();5 //set various timeout periods6CBCC. Socketpool.receivetimeout =NewTimeSpan (0,0,2);7CBCC. Socketpool.connectiontimeout =NewTimeSpan (0,0,4);8CBCC. Socketpool.deadtimeout =NewTimeSpan (0,0,Ten);9 //Use the default databaseTenCBCC. Urls.add (NewUri ("Http://127.0.0.1:8091/pools/default")); One A //setting up a client, loading the client's configuration -Couchbaseclient client =Newcouchbaseclient (CBCC); - //add a piece of data thecasresult<BOOL> casresult = client. Cas (Storemode.add,"Test","Hello world!"); - //get the data you just added -Console.WriteLine (client. Get ("Test")); -Console.WriteLine ("done! "); + console.readline (); -}
the difference between Storemode.add, Storemode.replace and Storemode.set
Add: Indicates the addition of a new key;
Replace: Indicates that an existing key is updated;
Set: Indicates that if key does not exist, it is added, the update is present.
Couchbaseclient is added (Cas), removed (remove), and other methods, pending further study.
The cache value results for the first run run get settings are:
Here is a comment on the value of this sentence: casresult<bool> casresult = client. Cas (Storemode.add, "Test", "Hello world!");
Run the value again or get it:
Other test results:
The Web backend can also see the added data, and it has been encrypted:
Iii. Summary
Easy to use down the feeling is very good, have time to continue to study. Here is a Couchbase installation configuration and instructions for use.
C # distributed Cache Couchbase use