Rocket Cos. said it would pay $1.8 billion in stock for the online real-estate agency Redfin Corp. in an effort to make it easier for customers to buy property using their mobile devices.