Psalm 31's title says it is for the Chief Musician and is a Psalm by David. It is a prayer that swings between distress and confidence, showing how faith works in real life. David opens, In you, Yahweh, I take refuge. Let me never be disappointed. He asks God to be a strong rock and a house of defense, and he confesses, Into your hand I commend my spirit. You redeem me, Yahweh, God of truth. In the New Testament, Jesus speaks these words as he dies on the cross (Luke 23:46), and Stephen prays a similar prayer to Jesus (Acts 7:59).
The middle of the psalm is full of pain. David's life is spent with sorrow and his years with sighing. He even says his strength fails because of his iniquity. He has become a horror to acquaintances, forgotten like a dead man, like broken pottery. He hears slander and terror on every side as people plot against him.
Then come the words that hold the psalm together: But I trust in you, Yahweh. I said, You are my God. My times are in your hand. Every moment of his life is under God's control. David praises God's goodness laid up for those who fear him and the shelter of God's presence. He admits that in his haste he said he was cut off, nevertheless God heard him. So he calls all the saints: Oh love Yahweh. Be strong, and let your heart take courage, all you who hope in Yahweh.