Rigidity for the spectral gap on Rcd(K, ∞)-spaces