Exemplo n.º 1
0
        public static async Task AddWaitingUser(WaitingUser user, long user_no)
        {
            // 이전에 등록되었던 유저면 삭제
            var u = await db.StringGetAsync($"waiting_user:{user_no}");

            if (u.HasValue)
            {
                var already_exist_user = JsonConvert.DeserializeObject <WaitingUser>(u);

                // 이전에 등록한 맵,랭크와  다를 경우 삭제 후 다시 등록
                // 다르지 않은데 삭제할 경우 매칭 순서가 뒤로 밀림
                if (user.map_id != already_exist_user.map_id || user.rank != already_exist_user.rank)
                {
                    await db.ListRemoveAsync($"waiting_list:{already_exist_user.map_id}:{already_exist_user.rank}", user_no);

                    await db.ListRightPushAsync($"waiting_list:{user.map_id}:{user.rank}", user_no);
                }
            }
            else
            {
                await db.ListRightPushAsync($"waiting_list:{user.map_id}:{user.rank}", user_no);
            }

            if ((await db.StringSetAsync($"waiting_user:{user_no}", JsonConvert.SerializeObject(user), waiting_user_expire)) == false)
            {
                Log.Error($"AddWaitingUser waiting_user:{user_no}");
            }
        }
Exemplo n.º 2
0
        public static async Task TestCache()
        {
            var u1 = new WaitingUser()
            {
                map_id = 1, rank = 1,
            };
            var u2 = new WaitingUser()
            {
                map_id = 1, rank = 1,
            };
            var u3 = new WaitingUser()
            {
                map_id = 1, rank = 1,
            };
            var u4 = new WaitingUser()
            {
                map_id = 1, rank = 1,
            };
            var u5 = new WaitingUser()
            {
                map_id = 1, rank = 1,
            };

            await WaitingList.AddWaitingUser(u1, 1);

            await Task.Delay(10 * 1000);

            await WaitingList.AddWaitingUser(u2, 2);

            await WaitingList.AddWaitingUser(u3, 3);

            await WaitingList.AddWaitingUser(u4, 4);

            await WaitingList.AddWaitingUser(u5, 4);

            var ret1 = await WaitingList.GetWaitingUser(1, 1, 3);


            var ret2 = await WaitingList.GetWaitingUser(1, 1, 3);


            var ret3 = await WaitingList.RemoveWaitingUser(3);

            await WaitingList.RemoveWaitingUser(1, 1, 2);
        }