I don't think you can put fungus gnats and cactus in the same sentence. Fungus gnats need two things to survive: damp soil and fungus. Usually, the larvae are feeding on fungus and rotting material (including rotting plant roots) in the soil but if they get desperate, they will bite healthy roots creating an opening into the root for a fungal infection.
But... cactus require really dry soil. The fungus gnat larvae will hibernate until conditions are better for them but I have never heard of them infesting cactus. Is your soil staying too wet for too long?
Insecticidal soap used as a drench will kill the larvae as will spraying the surface of the soil with full strength rubbing alcohol (70% isopropyl alcohol). Please note that rubbing alcohol and drinking alcohol are not the same thing.