Пример #1
0
        public async Task <Room> JoinRoom(string roomId, string playerName)
        {
            var room = await redis.GetAsync <Room>(roomId);

            room.players[Context.ConnectionId] = playerName;
            await redis.SetAsync(room.id, room);

            await Groups.AddToGroupAsync(Context.ConnectionId, room.id);

            await Clients.OthersInGroup(room.id).SendAsync("PlayerJoined", Context.ConnectionId, playerName);

            return(room);
        }
Пример #2
0
        private async Task IncrementKeyInsideLock(String key, String lockKey, int clientNo, IRedisClientAsync client)
        {
            await using (await client.AcquireLockAsync(lockKey))
            {
                Debug.WriteLine(String.Format("client {0} acquired lock", clientNo));
                var val = await client.GetAsync <int>(key);

                await Task.Delay(200);

                await client.SetAsync(key, val + 1);

                Debug.WriteLine(String.Format("client {0} released lock", clientNo));
            }
        }