Write in front
Recently, the company engaged in a campaign, using the Redis queue, the study of the next Redis related content. Also handy to do a demo.
Using Redis for C #
The associated assemblies for Reidis can be installed through NuGet. After installation, it is discovered that the following DLLs are introduced
Some list, queue, and Hashtable operations.
UsingSystem;UsingSystem.Collections.Generic;UsingSystem.Linq;UsingSystem.Text;UsingSystem.Threading.Tasks;UsingNservicekit.redis;UsingNewtonsoft.json;Namespaceredisdemo{Classprogram {Staticvoid Main (String[] args) {//Create a redis factory redisclientfactory factory =Redisclientfactory.instance;//Create Redisclient object Redisclient client = Factory through the factory. Createredisclient ("192.168.1.37",6379);//Adds a key-value pair to the client in the list. Additemtolist ("Test_listid","Wolfy");//Value by key and indexString value = client. Getitemfromlist ("Test_listid",0);//Queuefor (int i =0; I <10; i++) {client. Enqueueitemonlist ("Queue_test","Test" +i.ToString ()); }while (client. GetListCount ("Queue_test") >0{Console.WriteLine (client). Dequeueitemfromlist ("Queue_test")); }//Hashtablefor (int i =0; I <10; i++) {client. Setentryinhash ("Hashtable_test","Test "+ i.tostring (), Jsonconvert.serializeobject (new {id = i + 1, name = " wolfy I. ToString ()})); } // Gets the value in Hashtable list< string> lst = client. Gethashvalues ( "hashtable_test "); foreach (var item in LST) {Console.WriteLine (item);} Console.read (); } }}
Test
Summarize
About Redis Articles online There are many, here because of work needs, first started to get a demo, first run up, and then in-depth study.
Reprint: Blog Address: http://www.cnblogs.com/wolf-sun/
C # Redis Practice list,hashtable