Exemple #1
0
        // 레디스 테스트(List) 추가
        private async void button8_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxRedisTestList.Text))
            {
                DevLog.Write("Error: 빈 값입니다");
                return;
            }

            var value = await RedisLib.AddList <string>(REDIS_LIST_KEY, textBoxRedisTestList.Text);

            DevLog.Write(string.Format("List 추가. {0} : {1}. Count:{2})", REDIS_LIST_KEY, textBoxRedisTestList.Text, value));
        }
Exemple #2
0
        // 한번에 여러 아이템 추가
        private async void button22_Click(object sender, EventArgs e)
        {
            var ItemList = new List <int>();

            var parseData = textBox7.Text.Split(",");

            foreach (var id in parseData)
            {
                ItemList.Add(id.ToInt32());
            }

            var result = await DBWorkUserBasic.InsertItem(textBox9.Text, ItemList);

            DevLog.Write(string.Format("{0} 유저에게 {1}개의 아이템 추가. 결과:{2}", textBox9.Text, ItemList.Count, result));
        }
        public static async Task <long> AddList <T>(string key, T value)
        {
            try
            {
                var redis  = new RedisList <T>(redisGroupBasic, key);
                var result = await redis.LeftPush(value);

                return(result);
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.Message);
                return(0);
            }
        }
        public static async Task <List <T> > GetList <T>(string key, int startPos)
        {
            try
            {
                var redis  = new RedisList <T>(redisGroupBasic, key);
                var result = await redis.Range(startPos, -1);

                return(result.ToList());
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.Message);
                return(null);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value">이 값과 같은 것만 지운다</param>
        /// <param name="count">삭제할 개수. count가 0 보다 크면 왼쪽에서, count가 0 보다 작으면 오른쪽에서, 0과 같으면 모두 지운다</param>
        /// <returns></returns>
        public static async Task <long> DeleteList <T>(string key, T value, int count)
        {
            try
            {
                var redis  = new RedisList <T>(redisGroupBasic, key);
                var result = await redis.Remove(value, count);

                return(result);
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.Message);
                return(0);
            }
        }
        //****** float은 사용불가. 대신 double 사용 가능

        public static async Task <bool> SetString <T>(string key, T dataObject)
        {
            try
            {
                var redis  = new RedisString <T>(redisGroupBasic, key);
                var result = await redis.Set(dataObject);

                return(result);
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.Message);
                return(false);
            }
        }
        public static async Task <Int64> Increment(string key, Int64 value)
        {
            try
            {
                var redis  = new RedisString <Int64>(redisGroupBasic, key);
                var result = await redis.Increment(value);

                return(result);
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.Message);
                return(0);
            }
        }
Exemple #8
0
        // 레디스 테스트(List) 삭제
        private async void button10_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxRedisTestListCount.Text))
            {
                DevLog.Write("Error: 빈 값입니다");
                return;
            }
            else
            {
                var deleteValue = textBoxRedisTestList.Text;
                int count       = textBoxRedisTestListCount.Text.ToInt32();
                var value       = await RedisLib.DeleteList <string>(REDIS_LIST_KEY, deleteValue, count);

                DevLog.Write(string.Format("List 삭제. {0} : {1})", REDIS_LIST_KEY, value));
            }
        }
Exemple #9
0
        // GameUser2 검색: 이름 + 나이
        private async void button19_Click(object sender, EventArgs e)
        {
            var findUserName = textBox5.Text;

            var users = await DBWorkUserBasic.GetGameUser2(findUserName, textBox4.Text.ToInt32());

            if (users.Count() > 0)
            {
                foreach (var user in users)
                {
                    DevLog.Write(string.Format("GameUser2:{0}, Age:{1}, Nick:{2},{3}", user._id, user.Age, user.NickNameList[0], user.NickNameList[1]));
                }
            }
            else
            {
                DevLog.Write(string.Format("GameUser2:{0}를 찾을 수 없습니다", findUserName));
            }
        }
Exemple #10
0
        // GameUser1 검색
        private async void button14_Click(object sender, EventArgs e)
        {
            var findUserName = textBox3.Text;

            var users = await DBWorkUserBasic.GetGameUser1(findUserName);

            if (users.Count() > 0)
            {
                foreach (var user in users)
                {
                    DevLog.Write(string.Format("GameUser1:{0}, Age:{1}", user.Name, user.Age));
                }
            }
            else
            {
                DevLog.Write(string.Format("GameUser1:{0}를 찾을 수 없습니다", findUserName));
            }
        }
Exemple #11
0
        // 레디스 테스트(List) 검색
        private async void button9_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxRedisTestListR1.Text) ||
                string.IsNullOrEmpty(textBoxRedisTestListR2.Text))
            {
                var value = await RedisLib.GetList <string>(REDIS_LIST_KEY, 0);

                DevLog.Write(string.Format("List 추가. {0} : {1})", REDIS_LIST_KEY, string.Join(",", value)));
            }
            else
            {
                int pos1  = textBoxRedisTestListR1.Text.ToInt32();
                int pos2  = textBoxRedisTestListR2.Text.ToInt32();
                var value = await RedisLib.GetList <string>(REDIS_LIST_KEY, pos1, pos2);

                DevLog.Write(string.Format("List 추가. {0} : {1})", REDIS_LIST_KEY, string.Join(",", value)));
            }
        }
Exemple #12
0
        // 레디스 테스트(PERSION) 추가
        private async void button7_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxRedisTestPName.Text) ||
                string.IsNullOrEmpty(textBoxRedisTestPAge.Text))
            {
                DevLog.Write("Error: 이름이나 나이가 빈 값입니다");
                return;
            }

            var persion = new PERSION()
            {
                Name = textBoxRedisTestPName.Text, Age = textBoxRedisTestPAge.Text.ToInt32()
            };

            await RedisLib.SetString <PERSION>(REDIS_PERSION_KEY, persion);

            DevLog.Write(string.Format("PERSION Set. {0} : {1}, {2}", REDIS_PERSION_KEY, persion.Name, persion.Age));
        }
Exemple #13
0
        // 수정: 닉네임
        private async void button20_Click(object sender, EventArgs e)
        {
            var findUserName    = textBox5.Text;
            var newNickNameList = new List <string>()
            {
                textBox1.Text, textBox6.Text
            };

            var result = await DBWorkUserBasic.UpdateGameUser2(findUserName, newNickNameList);

            if (result == null)
            {
                DevLog.Write(string.Format("GameUser2:{0} 닉네임 변경 실패", findUserName));
            }
            else
            {
                DevLog.Write(string.Format("GameUser2:{0} 닉네임 변경 {1}, {2}", findUserName, result.NickNameList[0], result.NickNameList[1]));
            }
        }
        public static async Task <Tuple <bool, T> > GetString <T>(string key)
        {
            try
            {
                var redis = new RedisString <T>(redisGroupBasic, key);
                var value = await redis.Get();

                if (value.Value == null)
                {
                    return(Tuple.Create(false, default(T)));
                }

                return(Tuple.Create(true, value.Value));
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.Message);
                return(Tuple.Create(false, default(T)));
            }
        }
Exemple #15
0
        // 레디스 테스트(int, float, string) 추가
        private async void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(textBoxRedisTestInt.Text) == false)
                {
                    await RedisLib.SetString <int>(REDIS_INT_KEY, textBoxRedisTestInt.Text.ToInt32());

                    DevLog.Write(string.Format("String Set. {0} : {1}", REDIS_INT_KEY, textBoxRedisTestInt.Text));
                }

                if (string.IsNullOrEmpty(textBoxRedisTestDouble.Text) == false)
                {
                    await RedisLib.SetString <double>(REDIS_DOUBLE_KEY, textBoxRedisTestDouble.Text.ToDouble());

                    DevLog.Write(string.Format("String Set. {0} : {1}", REDIS_DOUBLE_KEY, textBoxRedisTestDouble.Text));
                }

                if (string.IsNullOrEmpty(textBoxRedisTestString.Text) == false)
                {
                    if (checkBoxAlreadyExit.Checked == false)
                    {
                        var result = await RedisLib.SetString <string>(REDIS_STRING_KEY, textBoxRedisTestString.Text);

                        DevLog.Write($"[{result}] String Set. {REDIS_STRING_KEY} : {textBoxRedisTestString.Text}");
                    }
                    else
                    {
                        var result = await RedisLib.SetStringAsyncWhenNotExists <string>(REDIS_STRING_KEY, textBoxRedisTestString.Text);

                        DevLog.Write($"[{result}] String Set. {REDIS_STRING_KEY} : {textBoxRedisTestString.Text}");
                    }
                }

                textBoxRedisTestInt.Text = textBoxRedisTestDouble.Text = textBoxRedisTestString.Text = "";
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.ToString());
            }
        }
Exemple #16
0
        // GameUser2 검색: 이름
        private async void button17_Click(object sender, EventArgs e)
        {
            var findUserName = textBox5.Text;

            var users = await DBWorkUserBasic.GetGameUser2(findUserName);

            if (users.Count() > 0)
            {
                foreach (var data in users)
                {
                    var age      = data["Age"].AsInt32;
                    var nickList = data["NickNameList"].AsBsonArray.Select(p => p.AsString).ToList();

                    DevLog.Write(string.Format("GameUser2:{0}, Age:{1}, Nick:{2},{3}", findUserName, age, nickList[0], nickList[1]));
                }
            }
            else
            {
                DevLog.Write(string.Format("GameUser2:{0}를 찾을 수 없습니다", findUserName));
            }
        }
        public static ERROR_ID Init(string address)
        {
            try
            {
                var basicRedisConnectString = address.Split(",").ToList();
                var redisSettings           = new RedisSettings[basicRedisConnectString.Count];

                if (basicRedisConnectString.Count() > 0)
                {
                    for (int i = 0; i < basicRedisConnectString.Count(); ++i)
                    {
                        redisSettings[i] = new RedisSettings(basicRedisConnectString[i], db: 0);
                    }

                    redisGroupBasic = new RedisGroup(groupName: "Basic", settings: redisSettings);
                }

                // 초기에 연결하도록 한다.
                for (int i = 0; i < basicRedisConnectString.Count; ++i)
                {
                    var key    = i.ToString() + "_test";
                    var redis  = new RedisString <int>(redisGroupBasic, key);
                    var result = redis.Set(11);
                    if (result.Result == false)
                    {
                        return(ERROR_ID.REDIS_START_SET_TEST);
                    }
                }


                return(ERROR_ID.NONE);
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.ToString());
                return(ERROR_ID.REDIS_START_EXCEPTION);
            }
        }
Exemple #18
0
        // 레디스 연결
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var result = RedisLib.Init(textBoxRedisAddress.Text);
                if (result == ERROR_ID.NONE)
                {
                    DevLog.Write("Redis 접속 성공");

                    button2.Enabled = button3.Enabled = button4.Enabled = true;
                    button7.Enabled = button6.Enabled = button5.Enabled = true;
                    button8.Enabled = button9.Enabled = button10.Enabled = button11.Enabled = button12.Enabled = true;
                }
                else
                {
                    DevLog.Write(string.Format("레디스 접속 실패. {0}", result));
                }
            }
            catch (Exception ex)
            {
                DevLog.Write(ex.ToString());
            }
        }
Exemple #19
0
        // 레디스 테스트(PERSION) 검색
        private async void button6_Click(object sender, EventArgs e)
        {
            var value = await RedisLib.GetString <PERSION>(REDIS_PERSION_KEY);

            DevLog.Write(string.Format("PERSION Get. {0} : {1}, {2}. Result:{3}", REDIS_PERSION_KEY, value.Item2.Name, value.Item2.Age, value.Item1));
        }
Exemple #20
0
        // 레디스 테스트(PERSION) 삭제
        private async void button5_Click(object sender, EventArgs e)
        {
            var value = await RedisLib.DeleteString <PERSION>(REDIS_PERSION_KEY);

            DevLog.Write(string.Format("PERSION Delete. {0} : result({1})", REDIS_PERSION_KEY, value));
        }
Exemple #21
0
        // 레디스 테스트(List) 삭제. 오른쪽에서 Pop
        private async void button12_Click(object sender, EventArgs e)
        {
            var value = await RedisLib.DeleteList <string>(REDIS_LIST_KEY, false);

            DevLog.Write(string.Format("List 오른쪽에서 Pop. {0} : {1})", REDIS_LIST_KEY, value));
        }
Exemple #22
0
        // GameUser1 추가
        private async void button15_Click(object sender, EventArgs e)
        {
            var result = await DBWorkUserBasic.CreateGameUser1(textBox3.Text, textBox2.Text.ToInt32());

            DevLog.Write(string.Format("GameUser1:{0} 추가", textBox3.Text));
        }
Exemple #23
0
        // 레벨
        private async void button25_Click(object sender, EventArgs e)
        {
            var result = await DBWorkUserBasic.GetUserLevelAsyncVer1(textBox8.Text);

            DevLog.Write(string.Format("{0} 유저의 레벨: {1}", textBox8.Text, result));
        }
Exemple #24
0
        //https://github.com/Fody/ToString
        // 유저의 기본 게임데이터 검색
        private async void button24_Click(object sender, EventArgs e)
        {
            var result = await DBWorkUserBasic.GetUserAsyncVer1(textBox8.Text);

            DevLog.Write($"User: {result._id}, Level: {result.Level}, Exp: {result.Exp}");
        }
Exemple #25
0
        // 새로운 유저 기본 게임데이터 추가 방법 2
        private async void button21_Click(object sender, EventArgs e)
        {
            var result = await DBWorkUserBasic.CreateBasicDataAsyncVer2(textBox9.Text);

            DevLog.Write(string.Format("{0} 유저의 기본 게임데이터 추가 결과:{1}", textBox9.Text, result));
        }