Пример #1
0
        public void CheckCompletedTest()
        {
            var keys = new[] { "testkey1", "testkey2" };
            var vals = new[] { "1", "2" };

            RedisConnectionPool.SetExpire(keys, vals, 300);
            RedisConnectionPool.Process(c =>
            {
                var values = new List <string>();
                using (var p = c.CreatePipeline())
                {
                    foreach (var key in keys)
                    {
                        string k = key;
                        p.QueueCommand(cli => cli.Get <string>(k), v =>
                        {
                            values.Add(v);
                        });
                    }
                    p.Flush();
                }
                Trace.WriteLine(string.Join(",", values));
            });
            var watch = Stopwatch.StartNew();
            var data  = ShareCacheStruct.Get <ChildData>(1);

            data.Age++;
            bool result = CacheFactory.CheckCompleted();

            Trace.WriteLine("Queue result:" + result);
            WaitEnd(watch);
        }
Пример #2
0
        private static void Expire(GameSession session, int timeout)
        {
            if (session == null)
            {
                return;
            }
            var    user = MathUtils.ToJson(session.User);
            string sid  = session.KeyCode.ToString("N");

            RedisConnectionPool.SetExpire(string.Format("{0}:{1}", sessionRedisKey, sid), user, timeout);
        }
Пример #3
0
        private static void SaveTo(IList <GameSession> sessions)
        {
            try
            {
                if (sessions.Count == 0)
                {
                    return;
                }

                var keys   = new List <string>();
                var values = new List <string>();
                foreach (GameSession session in sessions)
                {
                    var user = MathUtils.ToJson(session.User);
                    keys.Add(string.Format("{0}:{1}", sessionRedisKey, session.KeyCode.ToString("N")));
                    values.Add(user);
                }
                RedisConnectionPool.SetExpire(keys.ToArray(), values.ToArray(), Timeout);
            }
            catch (Exception er)
            {
                TraceLog.WriteError("Save session to redis faild,{0}", er);
            }
        }