Problem BackGround
I've read YungPeng's article (A Very Insightful Article) about Consistency between Redis Cache and SQL Database, and the double delete method looks simple enough, so I was considering to move it to our code(C#).
Specifically, I wanted to implement the mutable operation in double delete which can be summarized as follows according to YungPeng:
- Delete the entry in Redis;
- Create, update or delete the data to MySQL;
- Sleep for a while (say 500ms);
- Delete the entry in Redis again.
Questions
However, I have two questions about this:
Waiting for the process to sleep 500ms, delete Redis then return to the caller (Step 3,4) seems very slow. Would it be reasonable to queue the task (that sleeps and clears Redis) first then return to caller without waiting for the task to complete?
If my suggestion in question 1 is reasonable, how would I do it in C#? Would the following code be acceptable?
public async Task WriteOperation()
{
await ClearRedis();
await WriteDB();
Task.Run( () => { // Sleep 0.5 seconds then clear Redis } ); // Notice how I didn't await this
return;
}
Is it really ok to never await the Task? Will it ever be excuted? Would that Task finish roughly around 0.5 seconds?
Thanks in advance!