In the book of Psalms we find that when David prayed, he prayed with a long-term optimism; meaning that he knew God was going to deliver him. How did he know this?
First of all we must know that God protects those who walk in righteousness, because they are His loved ones. David, even after all he had committed, he humbled onto God and repented. These were acts of righteousness, which were pleasing onto God. Another reason why David knew God was going to deliver him was because the reason they chased David, was because of God. God’s people will always be chased, because the acts they have to do go against human reason. However, God is pleased when we do what He asks, and that is why He delivers us.