IdGenerator icon indicating copy to clipboard operation
IdGenerator copied to clipboard

遇到一个奇怪的问题,hash非常不均匀

Open ankye opened this issue 1 year ago • 4 comments

image

ankye avatar Sep 08 '22 16:09 ankye

hash规则是按 uid % 8 user := &model.User{ UID: utils.GenUID(), AppID: "aaaa", Account: "", Email: "", OpenID: fmt.Sprintf("%d", utils.GenUID()), UUID: fmt.Sprintf("%d", utils.GenUID()), Name: "name", Channel: "test", Avatar: "avatar", Password: fmt.Sprintf("%d", utils.GenUID()), }

ankye avatar Sep 08 '22 16:09 ankye

ID不是连续的,每毫秒的第一个ID尾号是5。 可以用ID数值里的时间戳 % 8

yitter avatar Sep 09 '22 13:09 yitter

可以了,但是这样上线后就不能动态修改长度了,只能换另外的hash算法了

ankye avatar Sep 19 '22 16:09 ankye

最近在用kingshard,hash规则不能定义,用id就有问题了

ankye avatar Sep 28 '22 11:09 ankye