コード例 #1
0
ファイル: ContextFactory.cs プロジェクト: RahmanM/RedCache
        private static CachingFramework.Redis.Context Connect(string connection)
        {
            CachingFramework.Redis.Context context = null;

            Policy
            .Handle <DivideByZeroException>()
            .WaitAndRetry(new[]
            {
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromSeconds(150),
                TimeSpan.FromSeconds(200)
            }, (exception, timeSpan, retryCount, conxt) =>
            {
                // TODO: Log the exeption
                Debug.WriteLine(exception.Message);
            })
            .Execute(() =>
            {
                context = new CachingFramework.Redis.Context(connection, new JsonSerializer());
            });

            return(context);
        }
コード例 #2
0
        static void TestCachingFramework()
        {        //https://github.com/thepirat000/CachingFramework.Redis#serialization
            var context = new CachingFramework.Redis.Context("127.0.0.1:8379, connectRetry=10, abortConnect=false, allowAdmin=true"
                                                             , new MsgBufWrapper()
                                                             );
            var hash = context.Collections.GetRedisDictionary <int, Person>("Person:hash");

            hash.Add(1, new Person {
                ID = 1, Name = "Steve", Age = 20
            });
            hash.Add(2, new Person {
                ID = 2, Name = "David", Age = 88
            });
            var dv = hash.FirstOrDefault(L => L.Value.Name == "David");

            Console.WriteLine("dd {0} {1}", dv.Value.Name, dv.Value.Age);

            foreach (var v in hash)
            {
                Console.WriteLine("v {0} {1}", v.Value.Name, v.Value.Age);
            }
            //context.Cache.
        }