예제 #1
0
        public void UpdateItem(Item item)
        {
            var conf = new RedisEndpoint()
            {
                Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "******", Ssl = true, Port = 6380
            };

            using (IRedisClient client = new RedisClient(conf))
            {
                IRedisTypedClient <Item> itemClient = client.As <Item>();
                IRedisList <Item>        itemList   = itemClient.Lists["urn:item:" + item.ProductID];

                var index = itemList.Select((Value, Index) => new { Value, Index })
                            .Single(p => p.Value.Id == item.Id).Index;

                var toUpdateItem = itemList.First(x => x.Id == item.Id);

                //var index = itemList.IndexOf(toUpdateItem);

                toUpdateItem.Name  = item.Name;
                toUpdateItem.Price = item.Price;

                itemList.RemoveAt(index);
                if (itemList.Count - 1 < index)
                {
                    itemList.Add(toUpdateItem);
                }
                else
                {
                    itemList.Insert(index, toUpdateItem);
                }

                client.RemoveItemFromSortedSet("urn:Rank", item.Name);
                client.AddItemToSortedSet("urn:Rank", item.Name, item.Price);

                //Publis top 5 Ranked Items
                IDictionary <string, double> Data = client.GetRangeWithScoresFromSortedSet("urn:Rank", 0, 4);
                List <Item> RankList = new List <Item>();
                int         counter  = 0;
                foreach (var itm in Data)
                {
                    counter++;
                    RankList.Add(new Item()
                    {
                        Name = itm.Key, Price = (int)itm.Value, Id = counter
                    });
                }

                var itemJson = JsonConvert.SerializeObject(RankList);
                client.PublishMessage("Rank", itemJson);
                //---------------------------------------------
            }
        }
예제 #2
0
        public void TestList()
        {
            var client = cacheClient as RedisClient;
            IRedisTypedClient <UserInfoDto> typeClient = client.As <UserInfoDto>();
            IRedisList <UserInfoDto>        list       = typeClient.Lists["TestList"];

            var listUser = GetUsers();

            list.Clear();
            listUser.ForEach(t => list.Add(t));

            var item = list.First(t => t.StaffId == "StaffId_8");

            Console.WriteLine(item);
            Console.ReadLine();
        }