The film "Groundhog Day" has a plot centered around a character whose day repeats exactly the same way each day, and upon waking retains memory of the previous day. This is what I call a "time-loop," which has a full explanation on TVTropes.
What is the earliest known instance of this idea being used in a story?
Edit for clarification: one or a few main characters remember the previous iterations of their day, and their actions can alter the events of the day. However, after the end of the day, the character wakes up with memories in tact. The day then repeats in the same way, possibly with different events depending on what the main character tries to do in reacting to their situation.