This commit is contained in:
Sakurasan
2023-03-30 18:39:56 +08:00
parent 6a6fca6c88
commit b023fabd90
3 changed files with 11 additions and 7 deletions

View File

@@ -24,13 +24,16 @@ func LoadKeysCache() {
log.Println(err)
return
}
for _, key := range keys {
KeysCache.Set(key.Key, true, cache.NoExpiration)
for idx, key := range keys {
KeysCache.Set(to.String(idx), key.Key, cache.NoExpiration)
}
}
func FromKeyCacheRandomItem() string {
items := KeysCache.Items()
if len(items) == 1 {
return items[to.String(0)].Object.(string)
}
idx := rand.Intn(len(items))
item := items[to.String(idx)]
return item.Object.(string)