public void Can_Remove_value_from_IList() { var storeMembers = Factory.CreateList(); storeMembers.ForEach(List.Add); storeMembers.Remove(Factory.ExistingValue); List.Remove(Factory.ExistingValue); var members = List.ToList<T>(); Factory.AssertListsAreEqual(members, storeMembers); }
public void Can_Remove_value_from_IList() { var storeMembers = Factory.CreateList(); storeMembers.ForEach(List.Add); var equalItem = new CustomType() { CustomId = 4 }; storeMembers.Remove(equalItem); List.Remove(equalItem); var members = List.ToList <CustomType>(); Factory.AssertListsAreEqual(members, storeMembers); }
public ActionResult Index() { string message = string.Empty; string host = "localhost"; using (var redisClient = new RedisClient(host)) { //Create a 'strongly-typed' API that makes all Redis Value operations to apply against Phones IRedisTypedClient <Phone> redis = redisClient.As <Phone>(); //Redis lists implement IList<T> while Redis sets implement ICollection<T> IRedisList <Phone> mostSelling = redis.Lists["urn:phones:mostselling"]; IRedisList <Phone> oldCollection = redis.Lists["urn:phones:oldcollection"]; Person phonesOwner = new Person { Id = 7, Age = 90, Name = "OldOne", Profession = "sportsmen", Surname = "OldManSurname" }; // adding new items to the list mostSelling.Add(new Phone { Id = 5, Manufacturer = "Sony", Model = "768564564566", Owner = phonesOwner }); mostSelling.Add(new Phone { Id = 8, Manufacturer = "Motorolla", Model = "324557546754", Owner = phonesOwner }); var upgradedPhone = new Phone { Id = 3, Manufacturer = "LG", Model = "634563456", Owner = phonesOwner }; mostSelling.Add(upgradedPhone); // remove item from the list oldCollection.Remove(upgradedPhone); // find objects in the cache IEnumerable <Phone> LGPhones = mostSelling.Where(ph => ph.Manufacturer == "LG"); // find specific Phone singleElement = mostSelling.FirstOrDefault(ph => ph.Id == 8); //reset sequence and delete all lists redis.SetSequence(0); redisClient.Remove("urn:phones:mostselling"); redisClient.Remove("urn:phones:oldcollection"); } ViewBag.Message = message; return(View()); }
static void Main(string[] args) { string host = "localhost"; int port = 6379; string elementKey = "testKeyRedis"; using (RedisClient redisClient = new RedisClient(host, port)) { if (redisClient.Get <string>(elementKey) == null) { redisClient.Set(elementKey, "some cached value"); } Console.WriteLine("Item value is: {0}", redisClient.Get <string>(elementKey)); IRedisTypedClient <Phone> phones = redisClient.As <Phone>(); Phone phoneFive = phones.GetValue("5"); if (phoneFive == null) { phoneFive = new Redis.Phone { Id = 5, Manufacturer = "Apple", Model = "xxxx", Owner = new Person { Id = 1, Age = 90, Name = "OldOne", Profession = "teacher", Surname = "SurName" } }; } phones.SetValue(phoneFive.Id.ToString(), phoneFive); Console.WriteLine("Phone model is: {0}, Phone Owner Name is: {1}", phoneFive.Manufacturer, phoneFive.Owner.Name); IRedisList <Phone> mostSelling = phones.Lists["urn:phones:mostselling"]; IRedisList <Phone> oldCollection = phones.Lists["urn:phones:oldCollection"]; Person phoneOwner = new Person { Id = 7, Age = 90, Name = "OldOne", Profession = "teacher", Surname = "SurName" }; mostSelling.Add(new Phone { Id = 5, Manufacturer = "Apple", Model = "54321", Owner = phoneOwner }); oldCollection.Add(new Phone { Id = 8, Manufacturer = "Moto", Model = "111111", Owner = phoneOwner }); var upgradedPhone = new Phone { Id = 5, Manufacturer = "LG", Model = "12345", Owner = phoneOwner }; mostSelling.Add(upgradedPhone); Console.WriteLine("Phones in mostSelling list:"); foreach (Phone ph in mostSelling) { Console.WriteLine(ph.Id); } Console.WriteLine("Phones in oldCollection list:"); foreach (Phone ph in oldCollection) { Console.WriteLine(ph.Id); } oldCollection.Remove(upgradedPhone); IEnumerable <Phone> LGPhones = mostSelling.Where(ph => ph.Manufacturer == "LG"); foreach (Phone ph in LGPhones) { Console.WriteLine("LG phone Id: {0}, LG phone Model: {1}", ph.Id, ph.Model); } Phone singleElement = oldCollection.FirstOrDefault(ph => ph.Id == 8); Console.WriteLine("singleElement phone Id: {0}, singleElement phone Model: {1}", singleElement.Id, singleElement.Model); phones.SetSequence(0); redisClient.Remove("urn:phones:mostselling"); redisClient.Remove("urn:phones:oldCollection"); Console.WriteLine("urn:phones:mostselling Count: {0}", phones.Lists["urn:phones:mostselling"].Count); } Console.ReadKey(); }
private bool RemoveValueFromList(IRedisList list, T value) => list.Remove(this.Serialize(value));