コード例 #1
0
        public async Task TestAsync()
        {
            var client = new RedisClientContext();


            var string_set_result1 = await client.StringSetAsync("key11", DateTime.Now, TimeSpan.FromSeconds(30));

            var string_get_result1 = await client.StringGetAsync <DateTime>("key11", TimeSpan.FromSeconds(30));
        }
コード例 #2
0
        public void Test1()
        {
            var client = new RedisClientContext();

            //transaction
            var tran_result = client.ExcuteWithTransaction(
                tran =>
            {
                tran.StringSetAsync("tran1", "aaa", TimeSpan.FromSeconds(30));
                //tran.AddCondition(Condition.StringNotEqual("tran1", "11212"));
                tran.StringDecrementAsync("tran1", 1);
            });

            //batch
            client.ExcuteWithBatch(
                batch =>
            {
                batch.StringSetAsync("batch1", "11212", TimeSpan.FromSeconds(30));
                batch.StringIncrementAsync("batch2", 2);
            });

            //lock
            Parallel.For(0, 10000, item =>
            {
                var is_success = client.ExcuteWithLock("lock_key", db => db.StringIncrement("lock", item));
            });

            //string
            var string_set_result = client.StringSet("string1", DateTime.Now, TimeSpan.FromSeconds(30));
            var string_get_result = client.StringGet <DateTime>("string1", TimeSpan.FromSeconds(30));

            //hash
            var hash_set_result = client.HashSet("hash1", new Dictionary <string, int> {
                ["key1"] = 123, ["2"] = 456, ["3"] = 123
            }, TimeSpan.FromSeconds(30));
            var hash_get_result = client.HashGet <Dictionary <string, int> >("hash1", "key1", TimeSpan.FromSeconds(30));

            //list
            var list_enqueue = client.Enqueue("list1", 1);
            var list_dequeue = client.Dequeue <int>("list1");
            var list_page    = client.ListGetPaged <int>("list1");

            //set
            var set_add_result = client.SetAdd("set1", "123");
            var set_get_result = client.SetGetList <string>("set1");

            //zset
            var zset_add_result  = client.SortedSetAdd("zset1", 1, 1);
            var zset_rang_result = client.SortedSetByRankGetPaged <int>("zset1");
        }