Exemple #1
0
        /// <summary>
        /// 按昵称获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="nickName">昵称</param>
        /// <returns>实体</returns>
        public BaseUserEntity GetObjectByNickName(BaseUserInfo userInfo, string nickName)
        {
            BaseUserEntity entity = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseUserManager(dbHelper, userInfo);
                entity      = manager.GetObjectByNickName(nickName);
            });
            return(entity);
        }
Exemple #2
0
        /// <summary>
        /// 通过唯一用户名从Reids中获取
        /// </summary>
        /// <param name="nickName"></param>
        /// <returns></returns>
        public static BaseUserEntity GetObjectByNickNameByCache(string nickName)
        {
            // 2016-01-25 黄斌 添加, 从缓存中 通过唯一用户名获取
            BaseUserEntity result = null;

            if (string.IsNullOrEmpty(nickName))
            {
                return(result);
            }

            //存取Redis中的U:BNN:
            string key = "User:ByNickName:" + nickName.ToLower();
            string id  = string.Empty;

            using (var redisClient = PooledRedisHelper.GetReadOnlyClient())
            {
                id = redisClient.Get <string>(key);
                if (!string.IsNullOrWhiteSpace(id))
                {
                    result = GetObjectByCache(redisClient, id);
                }
            }

            if (result == null)
            {
                BaseUserManager manager = new BaseUserManager();
                result = manager.GetObjectByNickName(nickName);
                if (result != null)
                {
                    result.NickName = result.NickName.ToLower();
                    SetCache(result);
                }
            }

            return(result);
        }