mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-03-01 00:35:36 +08:00
上外网前准备
This commit is contained in:
46
dispatch/dao/account_redis.go
Normal file
46
dispatch/dao/account_redis.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const RedisPlayerKeyPrefix = "HK4E"
|
||||
|
||||
const (
|
||||
AccountIdRedisKey = "AccountId"
|
||||
AccountIdBegin uint64 = 1
|
||||
YuanShenUidRedisKey = "YuanShenUid"
|
||||
YuanShenUidBegin uint64 = 100000001
|
||||
)
|
||||
|
||||
func (d *Dao) GetNextAccountId() (uint64, error) {
|
||||
return d.redisInc(RedisPlayerKeyPrefix + ":" + AccountIdRedisKey)
|
||||
}
|
||||
|
||||
func (d *Dao) GetNextYuanShenUid() (uint64, error) {
|
||||
return d.redisInc(RedisPlayerKeyPrefix + ":" + YuanShenUidRedisKey)
|
||||
}
|
||||
|
||||
func (d *Dao) redisInc(keyName string) (uint64, error) {
|
||||
exist, err := d.redis.Exists(context.TODO(), keyName).Result()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if exist == 0 {
|
||||
var value uint64 = 0
|
||||
if keyName == AccountIdRedisKey {
|
||||
value = AccountIdBegin
|
||||
} else if keyName == YuanShenUidRedisKey {
|
||||
value = YuanShenUidBegin
|
||||
}
|
||||
err := d.redis.Set(context.TODO(), keyName, value, 0).Err()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
id, err := d.redis.Incr(context.TODO(), keyName).Result()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(id), nil
|
||||
}
|
||||
Reference in New Issue
Block a user