zoukankan      html  css  js  c++  java
  • 缓存到Redis中记录数据

    一。先配好 Redis

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

         我自己配好的地址。

     <appSettings>
        <add key="RedisUrl" value="10.10.4.50:7895" /> //域名
        <add key="Redisdata" value="12" /> //value=12 是第12个库
      </appSettings>
    

     写cs文件

      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 string[] { ConfigurationManager.AppSettings["RedisUrl"] });
                }
                catch (Exception ex)
                {
                    //PublicFunction.Log("" + ex.Message + "
    ");
                    //PublicFunction.Log("" + ex.StackTrace + "
    ");
                }
            }
    
            /// <summary>
            /// 缓存到Redis中
            /// </summary>
            /// <param name="key"></param>
            /// <param name="danhaoList"></param>
            public static void EnqueueList(string key, string obj)
            {
                using (var client = poolreds.GetClient())
                {
                    //队列使用 
                    if (obj != null)
                    {
                         client.AddItemToList(key, obj);
                    }
    
                    //client.Add(key, obj);
                }
            }
    
            /// <summary>
            /// 读取当前
            /// </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>
            /// 判断当前是否有记录
            /// </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>
            /// 清除Redis数据
            /// </summary>
            /// <returns></returns>
            public static void PopRedis()
            {
                using (var client = poolreds.GetClient())
                {
                    client.FlushDb();//清除Redis的数据
                }
            }
    
        }
    

     前台调用。

      RedisPool.EnqueueList( "lin"+DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString());
                label1.Text = "昨天点击次数:" + RedisPool.GetListCount("lin" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));
                label2.Text = "今天点击次数:" + RedisPool.GetListCount("lin" + DateTime.Now.ToString("yyyy-MM-dd"));
    
  • 相关阅读:
    GridView中获取UserControl Fred
    objectivec字符串类NSString的使用
    IPhone之AVAudioRecorder
    iPhone中用第三方工具(RegexKitLite)实现正则表达
    android实现底部菜单栏
    android 菜单设计
    Objective C内存管理——如何理解autorelease
    在iphone中使用正则表达式 — OgreKit 详解
    iphone开发者证书装多台电脑的方法
    iPhone sdk 4.0 正则表达式
  • 原文地址:https://www.cnblogs.com/linbicheng/p/4412373.html
Copyright © 2011-2022 走看看