/// <summary>
 /// 获取缓存的网点登录信息
 /// </summary>
 /// <param name="companyId">网点Id</param>
 public static BaseOrganizeLogOnEntity GetCache(string companyId)
 {
     using (var redisClient = PooledRedisHelper.GetCallLimitClient())
     {
         return(redisClient.Get <BaseOrganizeLogOnEntity>("OrganizeLogOn:" + companyId));
     }
 }
 /// <summary>
 /// 设置缓存
 /// </summary>
 /// <param name="entity">登录信息</param>
 public static void SetCache(BaseOrganizeLogOnEntity entity)
 {
     using (var redisClient = PooledRedisHelper.GetCallLimitClient())
     {
         SetCache(redisClient, entity);
     }
 }
Exemple #3
0
        /// <summary>
        /// 登录次数统计功能(通过缓存高速实时统计、统计键值还是有些问题、进行了改进)
        /// 2016-03-28 吉日嘎拉
        /// </summary>
        /// <param name="userInfo">用户</param>
        public static void LogOnStatistics(BaseUserInfo userInfo)
        {
            if (!BaseSystemInfo.LogOnStatistics)
            {
                return;
            }
            string key = string.Empty;

            using (var redisClient = PooledRedisHelper.GetCallLimitClient())
            {
                // 1: 登录次数统计
                // 1-1:当月的登录人数增加一,
                key = "LogOn:Count:" + DateTime.Now.ToString("yyyy-MM");
                redisClient.IncrementValue(key);
                redisClient.ExpireEntryAt(key, DateTime.Now.AddYears(1));
                // 1-2:当天的登录人数增加一,
                key = "LogOn:Count:" + DateTime.Now.ToString("yyyy-MM-dd");
                redisClient.IncrementValue(key);
                redisClient.ExpireEntryAt(key, DateTime.Now.AddYears(1));
                // 1-3:当前小时的登录人数加一。
                key = "LogOn:Count:" + DateTime.Now.ToString("yyyy-MM-dd:HH");
                redisClient.IncrementValue(key);
                redisClient.ExpireEntryAt(key, DateTime.Now.AddYears(1));

                // 2:不重复的登录统计
                // 2-1:当月的不重复登录人数增加一。
                key = "LogOn:UserCount:" + DateTime.Now.ToString("yyyy-MM");
                redisClient.AddItemToSet(key, userInfo.Id);
                redisClient.ExpireEntryAt(key, DateTime.Now.AddYears(1));
                // 2-2:当天的不重复登录人数增加一。
                key = "LogOn:UserCount:" + DateTime.Now.ToString("yyyy-MM-dd");
                redisClient.AddItemToSet(key, userInfo.Id);
                redisClient.ExpireEntryAt(key, DateTime.Now.AddYears(1));
                // 2-3:当前小时的不重复登录人数增加一。
                key = "LogOn:UserCount:" + DateTime.Now.ToString("yyyy-MM-dd:HH");
                redisClient.AddItemToSet(key, userInfo.Id);
                redisClient.ExpireEntryAt(key, DateTime.Now.AddYears(1));

                // 3:不重复的网点登录统计
                // 3-1:每天有多少个公司在登录系统
                key = "LogOn:CompanyCount:" + DateTime.Now.ToString("yyyy-MM-dd");
                redisClient.AddItemToSet(key, userInfo.CompanyId);
                redisClient.ExpireEntryAt(key, DateTime.Now.AddYears(1));
            }
        }
Exemple #4
0
        public static bool CallLimit(string keyName, DateTime expireAt, int limit)
        {
            bool result = false;

            using (var redisClient = PooledRedisHelper.GetCallLimitClient())
            {
                if (redisClient.ContainsKey(keyName))
                {
                    result = redisClient.IncrementValue(keyName) > limit;
                }
                else
                {
                    redisClient.IncrementValue(keyName);
                    // 设置过期时间
                    redisClient.ExpireEntryAt(keyName, expireAt);
                }
            }

            return(result);
        }