From 15772669e7f929cb6103dc97006908e699a04303 Mon Sep 17 00:00:00 2001 From: Jyotinder Singh Date: Fri, 22 Nov 2024 17:40:44 +0530 Subject: [PATCH] further improve zrange.watch result handling --- watch_connection.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/watch_connection.go b/watch_connection.go index ea3e9ea53..dbf3f618c 100644 --- a/watch_connection.go +++ b/watch_connection.go @@ -314,14 +314,20 @@ func parseZRangeResult(data interface{}) (interface{}, error) { return []string{}, nil } - // Check if we have scores by examining data structure - // If data has even length and alternate elements can be parsed as floats, - // we treat it as WITHSCORES result - hasScores := false - if len(dataList) > 1 { - if scoreStr, ok := dataList[1].(string); ok { - if _, err := strconv.ParseFloat(scoreStr, 64); err == nil { - hasScores = true + // Check if we have scores by examining ALL potential score positions + // Only consider it a WITHSCORES result if all even-indexed elements are valid floats + hasScores := len(dataList) > 1 && len(dataList)%2 == 0 // must have even number of elements + if hasScores { + // Check every alternate position (potential score positions) + for i := 1; i < len(dataList); i += 2 { + scoreStr, ok := dataList[i].(string) + if !ok { + hasScores = false + break + } + if _, err := strconv.ParseFloat(scoreStr, 64); err != nil { + hasScores = false + break } } }