Use Redis distributed locks

This commit is contained in:
Jacob Gunther
2023-07-19 21:08:58 -05:00
parent 2f46ca5611
commit 8554fd2064
8 changed files with 251 additions and 53 deletions

View File

@@ -116,6 +116,11 @@ type Plugin struct {
func GetJavaStatus(host string, port uint16, enableQuery bool) (*JavaStatusResponse, time.Duration, error) {
cacheKey := fmt.Sprintf("java:%v-%s-%d", enableQuery, host, port)
mutex := r.NewMutex(fmt.Sprintf("java-lock:%v-%s-%d", enableQuery, host, port))
mutex.Lock()
defer mutex.Unlock()
cache, ttl, err := r.Get(cacheKey)
if err != nil {
@@ -149,6 +154,11 @@ func GetJavaStatus(host string, port uint16, enableQuery bool) (*JavaStatusRespo
func GetBedrockStatus(host string, port uint16) (*BedrockStatusResponse, time.Duration, error) {
cacheKey := fmt.Sprintf("bedrock:%s-%d", host, port)
mutex := r.NewMutex(fmt.Sprintf("bedrock-lock:%s-%d", host, port))
mutex.Lock()
defer mutex.Unlock()
cache, ttl, err := r.Get(cacheKey)
if err != nil {