mirror of
https://github.com/Xevion/banner.git
synced 2025-12-09 10:06:34 -06:00
Fix nil key check, fix bad durations
This commit is contained in:
19
meta.go
19
meta.go
@@ -1,12 +1,17 @@
|
||||
package main
|
||||
|
||||
import log "github.com/rs/zerolog/log"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
log "github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// GetGuildName returns the name of the guild with the given ID, utilizing Redis to cache the value
|
||||
func GetGuildName(guildID string) string {
|
||||
// Check Redis for the guild name
|
||||
guildName, err := kv.Get(ctx, "guild:"+guildID+":name").Result()
|
||||
if err != nil {
|
||||
if err != nil && err != redis.Nil {
|
||||
log.Error().Err(err).Msg("Error getting guild name from Redis")
|
||||
return "err"
|
||||
}
|
||||
@@ -22,7 +27,7 @@ func GetGuildName(guildID string) string {
|
||||
log.Error().Err(err).Msg("Error getting guild name")
|
||||
|
||||
// Store an invalid value in Redis so we don't keep trying to get the guild name
|
||||
_, err := kv.Set(ctx, "guild:"+guildID+":name", "x", 60*5).Result()
|
||||
_, err := kv.Set(ctx, "guild:"+guildID+":name", "x", time.Minute*5).Result()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error setting false guild name in Redis")
|
||||
}
|
||||
@@ -31,7 +36,7 @@ func GetGuildName(guildID string) string {
|
||||
}
|
||||
|
||||
// Cache the guild name in Redis
|
||||
kv.Set(ctx, "guild:"+guildID+":name", guild.Name, 60*60*3)
|
||||
kv.Set(ctx, "guild:"+guildID+":name", guild.Name, time.Hour*3)
|
||||
|
||||
return guild.Name
|
||||
}
|
||||
@@ -40,7 +45,7 @@ func GetGuildName(guildID string) string {
|
||||
func GetChannelName(channelID string) string {
|
||||
// Check Redis for the channel name
|
||||
channelName, err := kv.Get(ctx, "channel:"+channelID+":name").Result()
|
||||
if err != nil {
|
||||
if err != nil && err != redis.Nil {
|
||||
log.Error().Err(err).Msg("Error getting channel name from Redis")
|
||||
return "err"
|
||||
}
|
||||
@@ -56,7 +61,7 @@ func GetChannelName(channelID string) string {
|
||||
log.Error().Err(err).Msg("Error getting channel name")
|
||||
|
||||
// Store an invalid value in Redis so we don't keep trying to get the channel name
|
||||
_, err := kv.Set(ctx, "channel:"+channelID+":name", "x", 60*5).Result()
|
||||
_, err := kv.Set(ctx, "channel:"+channelID+":name", "x", time.Minute*5).Result()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error setting false channel name in Redis")
|
||||
}
|
||||
@@ -65,7 +70,7 @@ func GetChannelName(channelID string) string {
|
||||
}
|
||||
|
||||
// Cache the channel name in Redis
|
||||
kv.Set(ctx, "channel:"+channelID+":name", channel.Name, 60*60*3)
|
||||
kv.Set(ctx, "channel:"+channelID+":name", channel.Name, time.Hour*3)
|
||||
|
||||
return channel.Name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user