github.com/yitter/idgenerator-go@v1.3.3/reg.go (about) 1 package main 2 3 import ( 4 "C" 5 ) 6 import "github.com/yitter/idgenerator-go/regworkerid" 7 8 // RegisterOne 注册一个 WorkerId,会先注销所有本机已注册的记录 9 // address: Redis连接地址,单机模式示例:127.0.0.1:6379,哨兵/集群模式示例:127.0.0.1:26380,127.0.0.1:26381,127.0.0.1:26382 10 // password: Redis连接密码 11 // db: Redis指定存储库,示例:1 12 // sentinelMasterName: Redis 哨兵模式下的服务名称,示例:mymaster,非哨兵模式传入空字符串即可 13 // maxWorkerId: WorkerId 最大值,示例:63 14 // minWorkerId: WorkerId 最小值,示例:30 15 // lifeTimeSeconds: WorkerId缓存时长(秒,3的倍数) 16 //export RegisterOne 17 func RegisterOne(address *C.char, password *C.char, db int, sentinelMasterName *C.char, minWorkerId int32, maxWorkerId int32, lifeTimeSeconds int32) int32 { 18 return regworkerid.RegisterOne(regworkerid.RegisterConf{ 19 Address: C.GoString(address), 20 Password: C.GoString(password), 21 DB: db, 22 MasterName: C.GoString(sentinelMasterName), 23 MinWorkerId: minWorkerId, 24 MaxWorkerId: maxWorkerId, 25 LifeTimeSeconds: lifeTimeSeconds, 26 }) 27 } 28 29 // RegisterMany 注册多个 WorkerId,会先注销所有本机已注册的记录 30 // address: Redis连接地址,单机模式示例:127.0.0.1:6379,哨兵/集群模式示例:127.0.0.1:26380,127.0.0.1:26381,127.0.0.1:26382 31 // password: Redis连接密码 32 // db: Redis指定存储库,示例:1 33 // sentinelMasterName: Redis 哨兵模式下的服务名称,示例:mymaster,非哨兵模式传入空字符串即可 34 // maxWorkerId: WorkerId 最大值,示例:63 35 // minWorkerId: WorkerId 最小值,示例:30 36 // totalCount: 获取N个WorkerId,示例:5 37 // lifeTimeSeconds: WorkerId缓存时长(秒,3的倍数) 38 //export RegisterMany 39 func RegisterMany(address *C.char, password *C.char, db int, sentinelMasterName *C.char, minWorkerId int32, maxWorkerId int32, totalCount int32, lifeTimeSeconds int32) []int32 { 40 return regworkerid.RegisterMany(regworkerid.RegisterConf{ 41 Address: C.GoString(address), 42 Password: C.GoString(password), 43 DB: db, 44 MasterName: C.GoString(sentinelMasterName), 45 MinWorkerId: minWorkerId, 46 MaxWorkerId: maxWorkerId, 47 TotalCount: totalCount, 48 LifeTimeSeconds: lifeTimeSeconds, 49 }) 50 } 51 52 // UnRegister 注销本机已注册的 WorkerId 53 //export UnRegister 54 func UnRegister() { 55 regworkerid.UnRegister() 56 } 57 58 // Validate 检查本地WorkerId是否有效(0-有效,其它-无效) 59 //export Validate 60 func Validate(workerId int32) int32 { 61 return regworkerid.Validate(workerId) 62 }