2021-02-24 23:18:29 +08:00
|
|
|
// Package util...
|
|
|
|
//
|
|
|
|
// Description : util...
|
|
|
|
//
|
2021-07-25 19:05:59 +08:00
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
2021-02-24 23:18:29 +08:00
|
|
|
//
|
|
|
|
// Date : 2021-02-24 11:04 下午
|
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spaolacci/murmur3"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetHashID ...
|
|
|
|
//
|
2021-07-25 19:05:59 +08:00
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
2021-02-24 23:18:29 +08:00
|
|
|
//
|
|
|
|
// Date : 11:04 下午 2021/2/24
|
|
|
|
func GetHashID(key interface{}) uint64 {
|
|
|
|
return murmur3.Sum64([]byte(fmt.Sprintf("%v", key)))
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetHashIDMod 获取hashID并取模
|
|
|
|
//
|
2021-07-25 19:05:59 +08:00
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
2021-02-24 23:18:29 +08:00
|
|
|
//
|
|
|
|
// Date : 11:07 下午 2021/2/24
|
|
|
|
func GetHashIDMod(key interface{}, shard int) int {
|
|
|
|
return int(GetHashID(key) % uint64(shard))
|
|
|
|
}
|