Characterization of the boundedness for a family of commutators on $L^p$