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); }
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)); } }