doocs/advanced-java

Is there an error about Delay-double-deletion's example code?

alanchenggang opened this issue · 14 comments

There is an error in the code about delayed-double-deletion in the article<如何保证缓存与数据库的双写一致性>

public void set(key, value) {
    putToDb(key, value);
    deleteFromRedis(key);
    // ... a few seconds later
    deleteFromRedis(key);
}

And i google about this concept got this picture
image

一堆自动回复啊

一堆自动回复啊

这个延时双删是有问题不?

都是先延迟一段时间,再次删除缓存。没啥问题哈

都是先延迟一段时间,再次删除缓存。没啥问题哈
我谷歌的都是这样的 类似环绕通知

public void set(key, value) {
 
    deleteFromRedis(key);
   putToDb(key, value);
    // ... a few seconds later
    deleteFromRedis(key);
}