finclip-app-manager/vendor/gitlab.finogeeks.club/finclip-backend-v2/finclip-redis/rand.go

32 lines
542 B
Go
Raw Permalink Normal View History

2023-11-02 18:36:36 +08:00
package fcredis
import (
"fmt"
"sync/atomic"
)
var (
keys = uint32(24)
ops = uint32(0)
)
func GetRandKeys(sourceKey string) []string {
if gMode == ModeSingle {
return []string{sourceKey}
}
desKeys := make([]string, 0, keys)
for i := uint32(0); i < keys; i++ {
desKeys = append(desKeys, fmt.Sprintf("%s_%d", sourceKey, i))
}
return desKeys
}
func GetRandKey(sourceKey string) string {
if gMode == ModeSingle {
return sourceKey
}
index := atomic.AddUint32(&ops, 1)
return fmt.Sprintf("%s_%d", sourceKey, index%keys)
}