您好,欢迎访问一九零五行业门户网

大区中分配玩家唯一ID的办法_MySQL

bitscn.com
大区中分配玩家唯一id的办法
mysql中除了使用auto_increment字段作为自增序号以外 还有另外一种办法 可以提供
唯一序列号并且可以由一张表完成对多个序列要求的满足。
大致如下:
1。创建一个简单表 
   create table seqtab
   ( iseqno int not null default 0,
     iseqtype int not null default 0);
2。插入一调记录
   insert into seqtab values(0,13);  // 0表示seqno初始值,13为seqtype,同一张表可对
多个应用提供seq序列服务
3。不管多进程 or 单进程对seqtab表同时进行访问,使用一下方法获取序列号
   1st->update seqtab set iseqno=last_insert_id(iseqno+1) where iseqtype=13;
   2nd->select last_insert_id();
4。因多进程对seqtab同时访问,进行update seqtab set iseqno=last_insert_id(iseqno+1);时,
数据库保证了update的事务
完整性,且last_insert_id()是与当前mysql连接相关的,所以多进程同时使用时,也不会冲突。
bitscn.com
其它类似信息

推荐信息