private void RedisAddTicket(string ticket, string userId) { RedisCacheUtils.Select(3); TimeSpan timespan = new TimeSpan(GrobalConfig.TicketTimeOut * TimeSpan.TicksPerSecond); RedisCacheUtils.Set(ticket, userId, timespan); }
/// <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; } }
/// <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; } }
/// <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; } }
/// <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; } }
/// <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; } }
/// <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; } }
/// <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; } }
/// <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; } }
private string RedisGetClient(string clientSessionId) { RedisCacheUtils.Select(2); return(RedisCacheUtils.Get <string>(clientSessionId)); }
private void RedisDelClient(string clientSessionId) { RedisCacheUtils.Select(2); RedisCacheUtils.Remove(clientSessionId); }
/// <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); }
private string RedisGetTicket(string ticket) { RedisCacheUtils.Select(3); return(RedisCacheUtils.Get <string>(ticket)); }
private void RedisDelTicket(string ticket) { RedisCacheUtils.Select(3); RedisCacheUtils.Remove(ticket); }