• Demon.Lee
    2019-09-12
    感觉用redis,最终还是需要结合程序以及MySQL来处理,因为排行榜展示,前端还是需要用户名的,光给个用户id不知道是谁,除非redis有序集合的member包含了用户id和name,请指正。

    作者回复: 通常一个功能用一种DBMS即可,所以会用到有序集合的member保存id和name。因为这些数据是需要高频访问的,所以放到redis中会更适合。如果想要查询更具体的数据,需要用户点击排行榜中的某个玩家的时候,可以使用MySQL来处理,比如查看这个玩家具体使用过哪些英雄,具体战绩如何等。

     2
     4
  • 石维康
    2019-09-12
    在生成数据时,把"temp = temp + create_time / 10000000000"换成 temp = temp +1 - create_time / 10000000000 哈哈

    作者回复: 不错的方法 哈哈

    
     3
  • ttttt
    2019-09-11
    注册时间排名靠后MySQL语法:create_time按照降序排列。
    SELECT (@rownum := @rownum + 1) AS user_rank, user_id, score, create_time
    FROM user_score, (SELECT @rownum := 0) b
    ORDER BY score DESC, create_time DESC

    作者回复: Good Job

    
     1
  • felix
    2019-09-14
    咨询老师一个关于ip匹配的索引问题:
    有一个IP的库表,每一条记录了一个开始ip和结束ip,然后想批量匹配ip,查询为何没有用上“联合索引KEY `ip_range_int` (`start_int`,`end_int`) USING BTREE”?要怎么设置索引才有效?
    CREATE TABLE `t_dt_ip` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `start_ip` char(15) DEFAULT NULL,
      `end_ip` char(15) DEFAULT NULL,
      `location` varchar(100) DEFAULT NULL,
      `start_int` int(10) unsigned DEFAULT '0',
      `end_int` int(10) unsigned DEFAULT '0',
      PRIMARY KEY (`id`),
      KEY `ip_range` (`start_ip`,`end_ip`) USING BTREE,
      KEY `ip_range_int` (`start_int`,`end_int`) USING BTREE
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

    explain update t_tmp_ip t, t_dt_ip i
    set t.ip_id = i.id
    where INET_ATON(t.ip_address) between i.start_int and i.end_int;
    | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
    | 1 | UPDATE | t | NULL | ALL | NULL | NULL | NULL | NULL | 1000 | 100.00 | NULL |
    | 1 | SIMPLE | i | NULL | ALL | ip_range_int | NULL | NULL | NULL | 541942 | 11.11 | Range checked for each record (index map: 0xC) |

    甚至加上单个字段索引也没有用??
    alter table `t_dt_ip` add index indx_t_dt_ip_start_int (start_int);
    mysql> explain select * from t_dt_ip i join t_tmp_ip t on 1= 1 where t.ip_address >= i.start_int limit 1;
    | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
    | 1 | SIMPLE | t | NULL | ALL | NULL | NULL | NULL | NULL | 73126 | 100.00 | NULL |
    | 1 | SIMPLE | i | NULL | ALL | ip_range_int,indx_t_dt_ip_start_int | NULL | NULL | NULL | 541942 | 33.33 | Range checked for each record (index map: 0xC) |
    展开
    
    
我们在线,来聊聊吧