mysql - 订单规则id怎么生成?
迷茫
迷茫 2017-04-17 12:57:33
0
7
419

最近在考虑订单id怎么生成。

全数字但是不要太长,同时orderId需要唯一。

简单的id自增长肯定不行,不仅位数不够,还会暴露业务量。

最近我考虑:

简单的时间戳+随机数+流水号计数器。

不知道大家有什么好的想法。

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(7)
迷茫

It mainly depends on your business volume.

Generally there are several ways:
1. User ID + year, month, day, hour, minute and second + random number + serial number. The number of digits in the random number and serial number is set according to the business volume, but within seconds, two 4's are enough. If your business volume is small, neither random numbers nor serial numbers are used.
Such as: 0424 201505291832 0001 2455

2. User id + md5 (user id + timestamp). However, using md5() for message digest may cause duplication. Although 36^32 seems large, there is no guarantee that the digested data will not be repeated. Or you can modify it based on md5().
For example: 0424 + md5(0424 201505291832), (no space in the middle) the generated summary is: 0424e13c2fe2f569da04b2aa411980dbfa28

洪涛

It’s usually timestamp + random number, and the amount per day won’t be too big

伊谢尔伦

Our order system uses "year, month, day, hour, minute and second" + 4-digit random number. In this way, theoretically, up to 999 orders can be created in 1 second. Of course, after the order number is generated, it needs to be checked for duplication.

伊谢尔伦

Simple timestamp + random number + serial number counter + classification id

The classification id refers to the need to write a mapping table in the database
For example
1-》Some kind of order
2-》Another kind of order
3-》Another kind of order

左手右手慢动作

What about UUID?

Ty80

Can I use a dialer?

阿神

User ID + simple timestamp (accurate to the hour) + (4-digit) serial number counter. For example, it is 6:00 on June 10, 2016, and then add the 4-digit serial number count (on the ID card) 4 digits should be enough, I personally think random numbers are not very useful), write it as 0424-2016-06-10-06-0001.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!