keyFunc.go 597 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3
package redis_key

import (
hujiebin's avatar
hujiebin committed
4
	"fmt"
hujiebin's avatar
hujiebin committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
	"os"
)

// 替换keyFmt中的${var}变量s
// param keyFmt 如 a_b_${var1}_${var2}
// param arg 是个数组,按照下标替换${var},越界就用var1字样
// return a_b_var1_var2
func ReplaceKey(keyFmt string, arg ...string) string {
	n := len(arg)
	if n <= 0 {
		return keyFmt
	}
	var i int
	return os.Expand(keyFmt, func(s string) (r string) {
		if i >= n {
			return s
		}
		r = arg[i]
		i++
		return
	})
hujiebin's avatar
hujiebin committed
26 27 28 29 30 31 32
}

const UserMedalMerge = "user:medalMerge:%d" // 勋章

func GetUserMedalMerge(userId uint64) string {
	return fmt.Sprintf(UserMedalMerge, userId)
}