A man who tried to suffocate a sex worker with a pillowcase has been jailed for two-and-a-half years.