Cache to Redis record data

Source: Internet
Author: User

One. First with Redis.

Http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2011/0406/7873.html

I have a good address for myself.

<appSettings>    <add key= "Redisurl" value= "10.10.4.50:7895"/>//Domain name    <add key= "Redisdata" value= "/>//value=12" is the 12th library  </appSettings>

Write CS file

  public static class Redispool {public static Pooledredisclientmanager poolreds; static int port = Convert.ToInt32 (configurationmanager.appsettings["Redisdata"].        ToString ()); Static Redispool () {try {poolreds = new Pooledredisclientmanager (port, new S            Tring[] {configurationmanager.appsettings["Redisurl"]}); } catch (Exception ex) {//publicfunction.log ("" + Ex.                Message + "\ r \ n"); PublicFunction.Log ("" + Ex.            StackTrace + "\ r \ n"); }}///<summary>//cache to Redis///</summary>//<param name= "key" > </param>//<param name= "danhaolist" ></param> public static void Enqueuelist (string key, String obj) {using (var client = poolreds.                   Getclient ()) {//queue using if (obj! = null) {  Client.                Additemtolist (key, obj); }//client.            ADD (key, obj); }}///<summary>//Read current///</summary>/<param name= "key" ></            param>//<returns></returns> public static string Dequeuemodel (String key) { using (var client = poolreds. Getclient ()) {string Danhao = client.                Getitemfromlist (key,0);            return Danhao; }}///<summary>//To determine whether there is a record currently///</summary>//<param name= "key" >            </param>///<returns></returns> public static long GetListCount (string key) { using (var client = poolreds. Getclient ()) {Long Count = client.                GetListCount (key);            return count;       }}///<summary>//clear Redis Data///</summary> <returns></returns> public static void Popredis () {using (var client = Poolreds . Getclient ()) {client. FLUSHDB ();//Clear Redis Data}}}

The foreground call.

  Redispool.enqueuelist ("Lin" +datetime.now.tostring ("Yyyy-mm-dd"), DateTime.Now.ToString ());            Label1. Text = "hits Yesterday:" + Redispool.getlistcount ("Lin" + DateTime.Now.AddDays (-1). ToString ("Yyyy-mm-dd"));            Label2. Text = "Hits Today:" + Redispool.getlistcount ("Lin" + DateTime.Now.ToString ("Yyyy-mm-dd"));

Cache to Redis record data

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.