示例#1
0
        private void RedisAddTicket(string ticket, string userId)
        {
            RedisCacheUtils.Select(3);
            TimeSpan timespan = new TimeSpan(GrobalConfig.TicketTimeOut * TimeSpan.TicksPerSecond);

            RedisCacheUtils.Set(ticket, userId, timespan);
        }
示例#2
0
 /// <summary>
 /// 通过sessionid获取用户
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 public virtual UserModel GetUser(string sessionId)
 {
     try
     {
         RedisCacheUtils.Select(1);
         return(RedisCacheUtils.Get <UserModel>(sessionId));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#3
0
 /// <summary>
 /// 当前账号在他地登录session 是否已经登录
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 public virtual string UserSession(string userId)
 {
     try
     {
         RedisCacheUtils.Select(0);
         return(RedisCacheUtils.Get <string>(GrobalConfig.RedisUserTitle + userId));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#4
0
 /// <summary>
 /// 当前用户
 /// </summary>
 /// <returns></returns>
 public virtual UserModel Current()
 {
     try
     {
         string sessionId = getCurrentSession();
         RedisCacheUtils.Select(1);
         return(RedisCacheUtils.Get <UserModel>(sessionId));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#5
0
 /// <summary>
 /// 只清理redis的用户
 /// </summary>
 public virtual void EmptyCurrentRedis()
 {
     try
     {
         UserModel user = Current();
         RedisCacheUtils.Select(0);
         RedisCacheUtils.Remove(GrobalConfig.RedisUserTitle + user.UserId);
         RedisCacheUtils.Select(1);
         RedisCacheUtils.Remove(HttpContext.Current.Session.SessionID);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#6
0
 /// <summary>
 /// 修改user
 /// </summary>
 /// <param name="sessionId"></param>
 /// <param name="user"></param>
 public virtual void UpdateUser(string sessionId, UserModel user)
 {
     try
     {
         //修改redis
         RedisCacheUtils.Select(0);
         RedisCacheUtils.Set(GrobalConfig.RedisUserTitle + user.UserId, sessionId, null);
         RedisCacheUtils.Select(1);
         RedisCacheUtils.Set(sessionId, user, null);
         //todo:修改session 暂时无法修改其他的session
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#7
0
        /// <summary>
        /// 删除登录信息
        /// </summary>
        /// <param name="userId"></param>
        public virtual void EmptyUser(string userId)
        {
            try
            {
                string userIdKey = GrobalConfig.RedisUserTitle + userId;

                RedisCacheUtils.Select(0);
                string otherSessionId = RedisCacheUtils.Get <string>(userIdKey);
                RedisCacheUtils.Remove(userIdKey);

                RedisCacheUtils.Select(1);
                RedisCacheUtils.Remove(otherSessionId);
                //todo:clear other session
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#8
0
 /// <summary>
 /// 获取所有在线用户
 /// </summary>
 /// <returns></returns>
 public virtual IDictionary <string, UserModel> GetAllOnLines()
 {
     try
     {
         RedisCacheUtils.Select(1);
         IEnumerable <string> keys = RedisCacheUtils.GetAllKey();
         if (keys.ToJson().Equals("[]"))
         {
             return(null);
         }
         IDictionary <string, UserModel> users = RedisCacheUtils.GetAll <UserModel>(keys);
         return(users);
     }
     catch (Exception ex)
     {
         LogUtils.myError(log, ex);
         throw ex;
     }
 }
示例#9
0
        /// <summary>
        /// 写入登录信息
        /// </summary>
        /// <param name="user">成员信息</param>
        public virtual void AddCurrent(UserModel user)
        {
            try
            {
                string sessionId = getCurrentSession();

                RedisCacheUtils.Select(0);
                RedisCacheUtils.Set(GrobalConfig.RedisUserTitle + user.UserId, sessionId, null);

                RedisCacheUtils.Select(1);
                RedisCacheUtils.Set(sessionId, user, null);

                WebHelperUtils.WriteSession(LoginUserKey, user);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#10
0
 private string RedisGetClient(string clientSessionId)
 {
     RedisCacheUtils.Select(2);
     return(RedisCacheUtils.Get <string>(clientSessionId));
 }
示例#11
0
 private void RedisDelClient(string clientSessionId)
 {
     RedisCacheUtils.Select(2);
     RedisCacheUtils.Remove(clientSessionId);
 }
示例#12
0
 /// <summary>
 /// client sessionId => cas sessionId
 /// </summary>
 /// <param name="clientSessionId"></param>
 /// <param name="casSessionId"></param>
 private void RedisAddClient(string clientSessionId, string casSessionId)
 {
     RedisCacheUtils.Select(2);
     RedisCacheUtils.Set(clientSessionId, casSessionId, null);
 }
示例#13
0
 private string RedisGetTicket(string ticket)
 {
     RedisCacheUtils.Select(3);
     return(RedisCacheUtils.Get <string>(ticket));
 }
示例#14
0
 private void RedisDelTicket(string ticket)
 {
     RedisCacheUtils.Select(3);
     RedisCacheUtils.Remove(ticket);
 }