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

ScoreServiceImpl是不是有问题? #2

Open
huangzhike opened this issue Jan 21, 2018 · 3 comments
Open

ScoreServiceImpl是不是有问题? #2

huangzhike opened this issue Jan 21, 2018 · 3 comments

Comments

@huangzhike
Copy link

        if (userFind != null) {
            jedisClient.zadd("Toptest", (double) user.getScore(), userFind);
            System.out.println("修改原有的!!!");
            return;
        }
        //如果没有就加进去嘛,根据排行榜来区分
        if (userList.size() >= 20) {
            if (user.getScore() + scoreCount > userList.get(19).getScore()) {
                System.out.println("大于排名20名中的最后一名就丢进缓存    :");
                System.out.println("userList    :" + userList.toString());
            }
        } else {
            System.out.println("排行榜小于20人就直接丢进缓存    :");
            if (userFind != null) {
                jedisClient.zadd("Toptest", (double) user.getScore(), user);
            }
            System.out.println("user   " + userFind);
        }

这里两个userFind != null,但是前面已经return了,所以后面永远不会被执行吧?
还有userList.size() >= 20里边说明也没干?

@FuZhucheng
Copy link
Owner

注释有把逻辑写清楚呀,一个是如果原来有就修改原来的;if (userList.size() >= 20) {后就是如果原来没有,就添加

@huangzhike
Copy link
Author

我的意思是说,当userFind != null 的时候,
两个if (userFind != null) ,在第一个里边return了,所以第二个if (userFind != null) 就永远不会执行,这个代码就没有意义了。
就是System.out.println("排行榜小于20人就直接丢进缓存 :");下面那句if不会执行

@FuZhucheng
Copy link
Owner

呃,抱歉,我的错。第二个的if (userFind != null)是没有意义的,马上修正。感谢提醒。

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

2 participants