示例#1
0
        public void UpdateUser(int userId)
        {
            //update cache,   already updated,then call this method

            //update redis
            var user    = GetUser(userId);
            var redisDb = GameManager.RedisMultiplexer.GetDatabase(0);
            var key     = user.GetType().FullName;
            var field   = userId;
            var value   = ProtoBufUtils.Serialize(user);

            redisDb.HashSet(key, field, value);

            //update mysql
            using (IDbConnection connection = GameManager.DbFactory.OpenDbConnection())
            {
                connection.Update(user);
            }
        }
示例#2
0
        public void AddUser(int userId)
        {
            var user = CreateUser(userId);

            //add to cache
            userCache.Add(userId.ToString(), user);
            //add to redis
            var redisDb = GameManager.RedisMultiplexer.GetDatabase(0);
            var key     = user.GetType().FullName;
            var field   = userId;
            var value   = ProtoBufUtils.Serialize(user);

            redisDb.HashSet(key, field, value);

            //add to mysql
            using (IDbConnection connection = GameManager.DbFactory.OpenDbConnection())
            {
                connection.Insert(user);
            }
        }
示例#3
0
        public void Load(int userId)
        {
            if (userCache[userId.ToString()] != null)
            {
                return;
            }
            //load from mysql
            User user;

            using (IDbConnection connection = GameManager.DbFactory.OpenDbConnection())
            {
                user = connection.SingleById <User>(userId);
            }
            //add to cache
            userCache.Add(userId.ToString(), user);
            //add to redis
            var redisDb = GameManager.RedisMultiplexer.GetDatabase(0);
            var key     = user.GetType().FullName;
            var field   = userId;
            var value   = ProtoBufUtils.Serialize(user);

            redisDb.HashSet(key, field, value);
        }