edwingeng / wuid Goto Github PK
View Code? Open in Web Editor NEWAn extremely fast globally unique number generator.
License: BSD 3-Clause "New" or "Revised" License
An extremely fast globally unique number generator.
License: BSD 3-Clause "New" or "Revised" License
问下啊,ID是趋势递增的么?
为什么将返回结果从uint64改成了int64呢?
If the process is restarted, the callback method is high 28, is it possible to repeat the id
2^64总量始终有限,低36位用完可以更新高28位+1,当高位超过后,有什么解决方案?
兵哥,tag参数是做什么用的啊
Are the IDs generated time sortable?
// A机房
once.Do(func() {
g=wuid.NewWUID("default",nil,wuid.WithSection(1))
g.LoadH24FromMysql(....
})
// B机房
once.Do(func() {
g=wuid.NewWUID("default",nil,wuid.WithSection(2))
g.LoadH24FromMysql(....
})
// 然后g在程序中作为全局变量,这样,两个g都不共享mysql,可以达到全局唯一吗
现在项目本身在使用最新v8版本,然后又需要单独实例化一个v6版本
调用wuid生成id后,会自动关闭数据库连接,导致后续数据库操作无法继续执行
package tools
import (
"database/sql"
"github.com/astaxie/beego/orm"
"github.com/edwingeng/wuid/mysql"
_"github.com/go-sql-driver/mysql"
)
var newDB = func() (*sql.DB,bool,error){
db,_ := orm.GetDB()
return db,true,nil
}
var g = wuid.NewWUID("default", nil)
func NewId() (uint64){
g.LoadH28FromMysql(newDB, "wuid")
return g.Next()
}
调用代码:
func AddUser(u *User) (int64, error) {
// db,err := orm.GetDB()
//fmt.Println(err)
o := orm.NewOrm()
u.Id = 74837477878
for i:=0;i<100;i++ {
fmt.Println(tools.NewId())
}
fmt.Println(u)
return o.Insert(u)
}
插入操作无法继续执行,
[ORM]2019/05/12 22:09:56 -[Queries/default] - [FAIL / db.Exec / 0.0ms] - [INSERT INTO sys_user
(id
, username
, password
, phone
, email
, name
, avatar
, salt
, status
, is_staff
, last_login_time
, login_error_times
, remark
, delete_flag
, create_by
, create_time
, update_by
, update_time
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] - 74837477878
, qingmumao
,
xxxxxxxx
, 13332978703
, [email protected]
, ,
, , `0`, `0`, `0`, `0`,
, 0
, 0
, 0
, 0
, 0
- sql: database is closed
this wuid design make too many tables in mysql .
What about https://github.com/segmentio/ksuid?
这个id生成器是有序的吗?我需要做排序
假如用wuid
来表示一个订单的ID, 存储到数据里里面推荐用它的字符串表示还是直接用数字呢?
如果存储的是数字, wuid
返回uint64
类型, 拿来做主键合适吗?
The behaviour of how the floor impacts the output isn't really documented and the term itself brings confusion.
From https://en.wikipedia.org/wiki/Floor_and_ceiling_functions :
In mathematics and computer science, the floor function is the function that takes as input a real number x, and gives as output the greatest integer less than or equal to x.
Based on this definition, when I specified a step of 1024 with a floor of 897 and H28 of 1 I didn't expect to receive a value of 0x00000010000003a7 followed by 0x0000001000000728 and 0x0000001000000aa9; given that 0xAA9 is much higher than the "floor" value. It's obvious why this is happening when looking at the code where next() returns n / floor * floor.
The best that I can see is this is somehow useful in order to make it less obvious what the "step" actually is, using a Real number as step and benefiting from rounding to nearest Integer, causing the steps to be +/- 1. A floor > 1 is also a requirement when used with obfuscation to hide the obfuscation values used.
However the main issue is that I couldn't find any documentation about this expected behaviour, so as a user of this library I ended up having to dig through the code to figure it out.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.