What can Redis do?

Source: Internet
Author: User

Here are two things that Redis can do:

1. Provide the cache function, as the cache server;

2. Lightweight Message Queuing (MQ) for use.

 <summary>///Redis Help class///</summary> public class Redishelper {//<summary> Put data into Message queue///</summary>//<param name= "listId" > Queue id</param>//<p Aram Name= "value" > Data </param> public static void Enqueue (string listId, String value) {u Sing (iredisclient client = RedisManager.ClientManager.GetClient ()) {client.            Enqueueitemonlist (listId, value);        } return; }///<summary>///Data extraction from Message queue///</summary>//<param name= "listId" > Queue id&            lt;/param>//<returns></returns> public static string Dequeue (String listId) { using (iredisclient client = RedisManager.ClientManager.GetClient ()) {return client.            Dequeueitemfromlist (LISTID); }}///<summary>//Out of message queueData//</summary>//<param name= "redisclient" ></param>//<param name= "listId "></param>///<returns></returns> public static string Dequeue (Iredisclient Redisclien        T, string listId) {return redisclient.dequeueitemfromlist (listId); }///<summary>//Redis Write///</summary>//<typeparam name= "T" ></typep aram>//<param name= "key" > Keys </param>///<param Name= "value" > Value </param>// /<param name= "CacheTime" > Cache time (minutes) </param>//<returns></returns> public static Boo L set<t> (string key, T value, int cacheTime = 0) {using (iredisclient client = Redismanager.clien Tmanager.getclient ()) {if (cacheTime <= 0) {return client .                Set<t> (key, value);          }      Return client.            Set<t> (key, Value, DateTime.Now.AddMinutes (CacheTime)); }}///<summary>//Redis read//</summary>//<typeparam name= "T" >& lt;/typeparam>//<param name= "key" > Keys </param>//<returns></returns> Pub Lic static T get<t> (string key) {using (iredisclient client = RedisManager.ClientManager.GetClien T ()) {return client.            Get<t> (key); }}}///<summary> Redis Management class///</summary> public class Redismanager {PU        Blic static Pooledredisclientmanager Clientmanager {get; private set;}            Static Redismanager () {redisclientmanagerconfig redisconfig = new Redisclientmanagerconfig ();            redisconfig.maxwritepoolsize = 128;            redisconfig.maxreadpoolsize = 128; Clientmanager = new Pooledredisclientmanager (New string[] {"127.0.0.1"}, new string[] {"127.0.0.1"}, Redisconfig); }    }

  

Message Queuing Data consumer Sample code:

JavaScriptSerializer serializer = new JavaScriptSerializer ();            Data consumer            while (true)            {                String data = Redishelper.dequeue ("Sendactiveemail");                if (data! = null)                {                    Emailmodel Emailmodel = (Emailmodel) serializer. Deserialize (data, typeof (Emailmodel));                    Console.WriteLine ("Send mail:" + emailmodel.mailto);                    Commonhelper.sendemail (Emailmodel.mailto, Emailmodel.subject, Emailmodel.body, true);                    Console.WriteLine ("Send mail Complete");                }                else                {                    thread.sleep;                }            }

  

What can Redis do?

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.