Any tenant or lessee of the lands or lots liable may pay the amount assessed against the property of which he is the tenant or lessee under the provisions of this division, or he may pay the price agreed on to be paid under the provisions of Section 5580, either before or after an action is brought, together with costs, to the contractor, or his assigns, or he may redeem the property, if sold on execution or decree for the benefit of the owner, within the time prescribed by law, and deduct the amount so paid from the rents due and to become due from him. For any sums so paid beyond the rents due from him, he shall have a lien upon and may retain possession of the land and lots until the amount so paid and advanced is satisfied, with legal interest, from accruing rents, or by payment by the owner.