• 缓存到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"));
    
  • 相关阅读:
    如何获取QQ的clientkey
    自动输入QQ密码
    Ext Tree 操作类
    QQ消息记录文件压缩方法
    见过最恶心的代码,发泄一下。。。
    今天尝试获取QQ的clientkey未果,做个记号
    用c# 调用并调试c++的代码
    托盘管理 隐藏/显示/单击/右键/双击/改变位置
    在XP下是可以查看进程命令行参数的
    充分利用你的“二脑”
  • 原文地址:https://www.cnblogs.com/linbicheng/p/4412373.html
Copyright © 2020-2023  润新知