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.
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'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. But the stability of the code is not good enough. 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:
Static voidMain (string[] args) { //Configure the serverCouchbaseclientconfiguration CBCC =Newcouchbaseclientconfiguration (); //set various timeout periodsCBCC. Socketpool.receivetimeout =NewTimeSpan (0,0,2); CBCC. Socketpool.connectiontimeout=NewTimeSpan (0,0,4); CBCC. Socketpool.deadtimeout=NewTimeSpan (0,0,Ten); //Use the default databaseCBCC. Urls.add (NewUri ("Http://127.0.0.1:8091/pools/default"));//Create a client, load the client configuration of couchbaseclient client = new Couchbaseclient (CBCC);//add a piece of data casresult<bool> Casresult = client. Cas (Storemode.add, "Test", "Hello world!"); -//gets the data that was just added to 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:
C # distributed Cache Couchbase use