redis实战课题
redis實戰課題
本課題主要圍繞用戶登錄時,直接到redis中查找用戶的登錄信息,密碼驗證、重置密碼、查詢所有用戶、顯示登錄次數最多的前3位
,最后通過(C# SQL)持久化到SQL Server 數據庫中。
1、環境搭建
2、介紹客戶端API
3、保存【初始化數據到redis】
4、登錄【發送登錄驗證碼,有效時間10分鐘】
5、重置密碼
6、顯示登錄次數最多的3位用戶
7、持久化數據到SQL server 數據庫中。
?
代碼塊如下
public List<UserInfo> GetData(){//為簡便,這里使用窮舉例,不從DB中取數List<UserInfo> list = new List<UserInfo>() { new UserInfo(){Id=1001,Name="李雷1001",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1002,Name="李雷1002",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1003,Name="李雷1003",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1004,Name="李雷1004",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1005,Name="李雷1005",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1006,Name="李雷1006",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1007,Name="李雷1007",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1008,Name="李雷1008",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1009,Name="李雷1009",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1010,Name="李雷1010",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1011,Name="寒梅1011",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1012,Name="寒梅1012",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1013,Name="寒梅1013",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1014,Name="寒梅1014",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1015,Name="寒梅1015",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1016,Name="寒梅1016",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1017,Name="寒梅1017",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1018,Name="寒梅1018",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1019,Name="寒梅1019",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1020,Name="寒梅1020",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1021,Name="寒梅1021",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1022,Name="寒梅1022",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1023,Name="寒梅1023",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1024,Name="寒梅1024",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1025,Name="寒梅1025",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1026,Name="寒梅1026",age=101,Pwd="1234",sex="男",times=DateTime.Now },new UserInfo(){Id=1027,Name="寒梅1027",age=101,Pwd="1234",sex="男",times=DateTime.Now },};return list;}public void InitRedisData(){List<UserInfo> list = GetData();using (IRedisClient RClient = RedisManager.GetRedisClient()){IRedisTypedClient<UserInfo> IRUserInfo = RClient.As<UserInfo>();IRUserInfo.StoreAll(list);//foreach (var item in list)//{// RClient.StoreAsHash<UserInfo>(item);//}}}public void ResetPwd(string id, string pwd, string newpwd){using (IRedisClient RClient = RedisManager.GetRedisClient()){IRedisTypedClient<UserInfo> IRUserinfo = RClient.As<UserInfo>();UserInfo userinfo = IRUserinfo.GetValue("urn:userinfo:" + id);userinfo.Pwd = newpwd;IRUserinfo.SetValue("urn:userinfo:" + id, userinfo);}}public List<UserInfo> GetRedisData(){List<UserInfo> list = new List<UserInfo>();using (IRedisClient RClient = RedisManager.GetRedisClient()){IRedisTypedClient<UserInfo> IRUserInfo = RClient.As<UserInfo>();list = (List<UserInfo>)IRUserInfo.GetAll().OrderByDescending(i => i.times).OrderByDescending(i => i.Name).Take(5).ToList();}return list;}
轉載于:https://www.cnblogs.com/sandyliu1999/p/5338206.html
總結
- 上一篇: 【Unity】2.11 了解游戏有哪些分
- 下一篇: 20160331数据文件offline与