Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

这里是否存在并发问题? #1

Open
yezhwi opened this issue Nov 5, 2016 · 2 comments
Open

这里是否存在并发问题? #1

yezhwi opened this issue Nov 5, 2016 · 2 comments

Comments

@yezhwi
Copy link

yezhwi commented Nov 5, 2016

public Exposer exportSeckillUrl(long seckillId) {
// 优化点:缓存优化:超时的基础上维护一致性
//1:访问redis
Seckill seckill = redisDao.getSeckill(seckillId);
if (seckill == null) {
//2:访问数据库
seckill = seckillDao.queryById(seckillId);
if (seckill == null) {
return new Exposer(false, seckillId);
} else {
//3:放入redis
redisDao.putSeckill(seckill);
}
}

这里在并发的时候,是不是会出现多次查询数据库,多次更新redis?
谢谢~

@RichardTibco
Copy link

RichardTibco commented Dec 8, 2016 via email

@geekyijun
Copy link
Owner

这个并发情况下会引起重复调用seckillDao.queryById,这个操作本事是primary key查询很快,且重复更新redis是幂等操作,可以忽略。如果是比较耗时的操作且有瞬时峰值流量,可以考虑mutex,见文档:https://timyang.net/programming/memcache-mutex/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants