/// <summary> /// 注册 /// </summary> /// <returns></returns> static bool Register(User user) { using (var helper = new DoRedisHash()) { helper.Core.SetRangeInHash("user:"******"Tokens", user.Token, user.ID); } return(true); }
/// <summary> /// 登陆 /// </summary> /// <param name="userId"></param> /// <param name="passWord"></param> static string Login(string userId, string passWord) { if (IsAuth(userId, passWord))//验证密码是否正确 { using (var helper = new DoRedisHash()) { //移除失效token var token = helper.GetValueFromHash("user:"******"Token"); helper.RemoveEntryFromHash("Tokens", token); token = Guid.NewGuid().ToString(); helper.SetEntryInHash("Tokens", token, userId); //更新到tokens散列 helper.SetEntryInHash("user:"******"Token", token); //更新用户token return(token); } } return(null); }
public string SetHash(string hashId, string key, string value) { string result = "success"; try { DoRedisHash rh = new DoRedisHash(); rh.SetEntryInHash(hashId, key, value); } catch (Exception ex) { result = ex.Message; } return(result); }