Exemplo n.º 1
0
        private void btnReset_Click(object sender, EventArgs e)
        {
            using (RedisClient client = new RedisClient("localhost", 6379))
            {
                IRedisTypedClient <Phone> phone = client.As <Phone>();
                phone.DeleteAll();
                phoneBindingSource.Clear();

                String new_id           = "J_0";
                String new_manufacturer = "010-Enterprise-";
                String new_Model        = "902-XXJ-";

                for (int i = 0; i < 3000; i++)
                {
                    Phone p = new Phone();
                    p.ID           = new_id + i;
                    p.Manufacturer = new_manufacturer + i;
                    p.Model        = new_Model + i;

                    phone.Store(p);
                }

                phoneBindingSource.DataSource = phone.GetAll();
                MetroFramework.MetroMessageBox.Show(this, "Your data has been succesfully reseted.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ClearText();
            }
        }
Exemplo n.º 2
0
        public void TestSet()
        {
            var client = cacheClient as RedisClient;
            IRedisTypedClient <UserInfoDto> typeClient = client.As <UserInfoDto>();

            typeClient.DeleteAll();
            IRedisSet <UserInfoDto> set = typeClient.Sets["TestSet"];
            var sortSet = typeClient.SortedSets["TestSet1"];

            var list = GetUsers();

            set.Clear();
            list.ForEach(x => set.Add(x));
            list.ForEach(x => sortSet.Add(x));

            Console.WriteLine("写入完成");
            Console.ReadLine();

            var item = sortSet.Where(t => t.StaffId == "StaffId_7").ToList();

            //var result =  set.GetAll();

            Console.WriteLine(item.ToString());
            Console.ReadLine();
        }
Exemplo n.º 3
0
 /// <summary>
 /// 删除所有
 /// 2016-03-28 23:48:18
 /// </summary>
 /// <typeparam name="T"></typeparam>
 public void DeleteAll <T>()
 {
     using (IRedisClient client = RedisManager.GetRedisWriteClient())
     {
         IRedisTypedClient <T> typedClient = client.As <T>();
         typedClient.DeleteAll();
     }
 }
 /// <summary>
 /// 删除所有缓存
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 public void DeleteAll <T>()
     where T : IHasId <string>
 {
     using (IRedisClient redisClient = PRM.GetClient())
     {
         using (IRedisTypedClient <T> typedclient = redisClient.As <T>())
         {
             typedclient.DeleteAll();
         }
     }
 }
Exemplo n.º 5
0
        public void Can_Delete_All_Items()
        {
            var cachedRecord = new CacheRecord
            {
                Id       = "key",
                Children =
                {
                    new CacheRecordChild {
                        Id = "childKey", Data = "data"
                    }
                }
            };

            RedisTyped.Store(cachedRecord);

            Assert.That(RedisTyped.GetById("key"), Is.Not.Null);

            RedisTyped.DeleteAll();

            Assert.That(RedisTyped.GetById("key"), Is.Null);
        }
Exemplo n.º 6
0
        public void Can_DeleteAll()
        {
            var tos = Factory.CreateList();
            redis.StoreAll(tos);

            var all = redis.GetAll();

            Assert.That(all.Count, Is.EqualTo(tos.Count));

            redis.DeleteAll();

            all = redis.GetAll();

            Assert.That(all.Count, Is.EqualTo(0));
        }
Exemplo n.º 7
0
 public bool DeleteRouletteRedis()
 {
     try
     {
         using (RedisClient client = new RedisClient("localhost", 6379))
         {
             IRedisTypedClient <Roulette> objRoulettes = client.As <Roulette>();
             objRoulettes.DeleteAll();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("ERROR: " + ex.Message);
         return(false);
     }
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            // ilk önce Sunucu ile aramızda bir kanal açalım
            using (RedisClient client = new RedisClient("127.0.0.1", 6379))
            {
                // T ile belirtilen tip ile çalışabileceğimiz bir Redis arayüzünü tedarik etmemizi sağlar
                IRedisTypedClient <Person> personStore = client.As <Person>();

                #region Örnek bir veri kümesinin eklenmesi

                // Temiz bir başlangıç için istenirse var olan Person kümesi silinebilir de
                if (personStore.GetAll().Count > 0)
                {
                    personStore.DeleteAll();
                }

                // Bir kaç örnek departman ve personel verisi oluşturuyoruz
                Department itDepartment = new Department
                {
                    DepartmentId = 1000,
                    Name         = "IT",
                    Description  = "Information Technologies"
                };
                Department financeDepartment = new Department
                {
                    DepartmentId = 1000,
                    Name         = "Finance",
                    Description  = "Finance Unit"
                };

                List <Person> persons = new List <Person>
                {
                    new Person
                    {
                        PersonId     = personStore.GetNextSequence()
                        , Name       = "Burak"
                        , Level      = 100
                        , Department = itDepartment
                    },
                    new Person
                    {
                        PersonId     = personStore.GetNextSequence()
                        , Name       = "Bill"
                        , Level      = 200
                        , Department = itDepartment
                    },
                    new Person
                    {
                        PersonId     = personStore.GetNextSequence()
                        , Name       = "Adriana"
                        , Level      = 250
                        , Department = itDepartment
                    },
                    new Person
                    {
                        PersonId     = personStore.GetNextSequence()
                        , Name       = "Sakira"
                        , Level      = 300
                        , Department = financeDepartment
                    },
                    new Person
                    {
                        PersonId     = personStore.GetNextSequence()
                        , Name       = "Bob"
                        , Level      = 550
                        , Department = financeDepartment
                    }
                };

                // Elemanları StoreAll metodu yardımıyla Redis' e alıyoruz.
                personStore.StoreAll(persons);

                #endregion Örnek bir veri kümesinin eklenmesi

                #region Verileri elde etmek, sorgulamak

                Console.WriteLine("Tüm Personel");
                // Kaydettiğimiz elemanların tamamını GetAll metodu yardımıyla çekebiliriz.
                foreach (var person in personStore.GetAll())
                {
                    Console.WriteLine(person.ToString());
                }

                // Dilersek içeride tutulan Key/Value çiftlerinden Key değerlerine ulaşabiliriz
                List <string> personKeys = personStore.GetAllKeys();

                Console.WriteLine("\nKey Bilgileri");
                foreach (var personKey in personKeys)
                {
                    Console.WriteLine(personKey);
                }

                // İstersek bir LINQ sorgusunu GetAll metodu üstünden dönen liste üzerinden çalıştırabiliriz
                IOrderedEnumerable <Person> itPersons = personStore
                                                        .GetAll()
                                                        .Where <Person>(p => p.Department.Name == "IT")
                                                        .OrderByDescending(p => p.Level);

                Console.WriteLine("\nSadece IT personeli");
                foreach (var itPerson in itPersons)
                {
                    Console.WriteLine(itPerson.ToString());
                }

                // Random bir Key değeri alabilir ve bunun karşılığı olan value' yu çekebiliriz
                string randomKey = personStore.GetRandomKey();
                Console.WriteLine("\nBulunan Key {0}", randomKey);
                // seq:Person ve ids:Person key değerleri için hata oluşacağından try...catch' den kaçıp başka bir kontrol yapmaya çalışıyoruz.
                if (randomKey != personStore.SequenceKey &&
                    randomKey != "ids:Person")
                {
                    var personByKey = personStore[randomKey];
                    Console.WriteLine("{0}", personByKey.ToString());
                }

                personStore.SaveAsync(); // Kalıcı olarak veriyi persist edebiliriz. Asenkron olarak yapılabilen bir işlemdir.

                #endregion Verileri elde etmek, sorgulamak

                Console.WriteLine("\nÇıkmak için bir tuşa basınız");
                Console.ReadLine();
            }
        }