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();
        }
Beispiel #2
0
        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);

                message += "Phones in mostSelling list: ";
                foreach (Phone ph in mostSelling)
                {
                    message += " Id : " + ph.Id;
                    message += " Model : " + ph.Model;
                }


                // 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());
        }