tdl/pkg/key/key.go
2022-09-01 15:16:59 +08:00

38 lines
587 B
Go

package key
import (
"bytes"
"strconv"
"strings"
"sync"
)
var keyPool = sync.Pool{
New: func() interface{} {
b := &bytes.Buffer{}
b.Grow(16)
return b
},
}
func New(indexes ...string) string {
buf := keyPool.Get().(*bytes.Buffer)
buf.WriteString(strings.Join(indexes, ":"))
t := buf.String()
buf.Reset()
keyPool.Put(buf)
return t
}
func Session() string {
return New("session")
}
func State(userID int64) string {
return New("state", strconv.FormatInt(userID, 10))
}
func StateChannel(userID int64) string {
return New("chan", strconv.FormatInt(userID, 10))
}