public static void Show() { UserInfo user = new UserInfo() { Id = 123, Account = "Administrator", Address = "武汉市", Email = "*****@*****.**", Name = "Eleven", Password = "******", QQ = 57265177 }; using (RedisStringService service = new RedisStringService()) { //service.Set<string>($"userinfo_{user.Id}", Newtonsoft.Json.JsonConvert.SerializeObject(user)); service.Set <UserInfo>($"userinfo_{user.Id}", user); var userCacheList = service.Get <UserInfo>(new List <string>() { $"userinfo_{user.Id}" }); var userCache = userCacheList.FirstOrDefault(); //string sResult = service.Get($"userinfo_{user.Id}"); //var userCache = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(sResult); userCache.Account = "Admin"; service.Set <UserInfo>($"userinfo_{user.Id}", userCache); } using (RedisHashService service = new RedisHashService()) { service.FlushAll(); //反射遍历做一下 service.SetEntryInHash($"userinfo_{user.Id}", "Account", user.Account); service.SetEntryInHash($"userinfo_{user.Id}", "Name", user.Name); service.SetEntryInHash($"userinfo_{user.Id}", "Address", user.Address); service.SetEntryInHash($"userinfo_{user.Id}", "Email", user.Email); service.SetEntryInHash($"userinfo_{user.Id}", "Password", user.Password); service.SetEntryInHash($"userinfo_{user.Id}", "Account", "Admin"); service.StoreAsHash <UserInfo>(user);//含ID才可以的 var result = service.GetFromHash <UserInfo>(user.Id); } UserInfo user2 = new UserInfo() { Id = 234, Account = "Administrator2", Address = "武汉市2", Email = "[email protected]", Name = "Eleven2", Password = "******", QQ = 572651772 }; using (RedisHashService service = new RedisHashService()) { service.FlushAll(); //反射遍历做一下 service.SetEntryInHash($"userinfo_{user2.Id}", "Account", user2.Account); service.SetEntryInHash($"userinfo_{user2.Id}", "Name", user2.Name); service.SetEntryInHash($"userinfo_{user2.Id}", "Address", user2.Address); service.SetEntryInHash($"userinfo_{user2.Id}", "Email", user2.Email); service.SetEntryInHash($"userinfo_{user2.Id}", "Remark", "这里是2号用户"); service.StoreAsHash <UserInfo>(user);//含ID才可以的 var result = service.GetFromHash <UserInfo>(user.Id); } }
static BaseSpider() { RedisClient = new RedisHashService(); RedisClient.FlushAll(); }