keys.go 1.13 KB
Newer Older
chenweijian's avatar
chenweijian committed
1 2 3 4
package user_k

import (
	"fmt"
hujiebin's avatar
hujiebin committed
5
	"git.hilo.cn/hilo-common/resource/mysql"
chenweijian's avatar
chenweijian committed
6
	"hilo-user/_const/redis_key"
hujiebin's avatar
hujiebin committed
7 8
	"strconv"
	"strings"
chenweijian's avatar
chenweijian committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
)

const (
	UserPrefix             = "user:"
	UserTinyInfoStr        = UserPrefix + "tiny:${userId}"           // value:json(cv.CvUserTiny)
	UserExternalIdToUIdStr = UserPrefix + "externalId:${externalId}" // value:userId
	UserCodeToUIdStr       = UserPrefix + "code:${externalId}"       // value:userId
	UserTradeUnionIds      = "user:trade:union:ids"                  // type:string,value json(uids)
)

// 获取用户简要信息缓存key
func GetUserTinyKey(userId mysql.ID) string {
	return redis_key.ReplaceKey(UserTinyInfoStr, fmt.Sprintf("%d", userId))
}

// 获取externalId到userId
func GetExternalIdToUidKey(externalId mysql.Str) string {
	return redis_key.ReplaceKey(UserExternalIdToUIdStr, externalId)
}

// 获取code到userId
func GetCodeToUidKey(code mysql.Str) string {
	return redis_key.ReplaceKey(UserCodeToUIdStr, code)
}
hujiebin's avatar
hujiebin committed
33 34 35 36 37 38

const syncTimHiloLock = "sync_tim_hilo_{userId}"

func GetKeySyncTimHilo(userId uint64) string {
	return strings.Replace(syncTimHiloLock, "{userId}", strconv.FormatUint(userId, 10), -1)
}