Redshifts for flat-spectrum radio sources in the second Caltech-Jodrell Bank VLBI sample