From 5d2b2bded92c727e199efdeaf40ba9ff299e9355 Mon Sep 17 00:00:00 2001 From: sashpawar11 Date: Sun, 20 Oct 2024 20:47:06 +0530 Subject: [PATCH] fix lint --- internal/eval/eval.go | 1 - internal/eval/store_eval.go | 46 ------------------------------------- internal/worker/cmd_meta.go | 10 ++++---- 3 files changed, 5 insertions(+), 52 deletions(-) diff --git a/internal/eval/eval.go b/internal/eval/eval.go index 1c0515206..958667653 100644 --- a/internal/eval/eval.go +++ b/internal/eval/eval.go @@ -2,7 +2,6 @@ package eval import ( "bytes" - "crypto/rand" "errors" "fmt" "log/slog" diff --git a/internal/eval/store_eval.go b/internal/eval/store_eval.go index 91438e87e..a7dfb2a9f 100644 --- a/internal/eval/store_eval.go +++ b/internal/eval/store_eval.go @@ -2,7 +2,6 @@ package eval import ( "fmt" - "crypto/rand" "math" "strconv" "strings" @@ -1182,51 +1181,6 @@ func evalHRANDFIELD(args []string, store *dstore.Store) *EvalResponse { return selectRandomFields(hashMap, count, withValues) } -// selectRandomFields returns random fields from a hashmap. -func selectRandomFields(hashMap HashMap, count int, withValues bool) *EvalResponse { - keys := make([]string, 0, len(hashMap)) - for k := range hashMap { - keys = append(keys, k) - } - - var results []string - resultSet := make(map[string]struct{}) - - abs := func(x int) int { - if x < 0 { - return -x - } - return x - } - - for i := 0; i < abs(count); i++ { - if count > 0 && len(resultSet) == len(keys) { - break - } - - randomIndex, _ := rand.Int(rand.Reader, big.NewInt(int64(len(keys)))) - randomField := keys[randomIndex.Int64()] - - if count > 0 { - if _, exists := resultSet[randomField]; exists { - i-- - continue - } - resultSet[randomField] = struct{}{} - } - - results = append(results, randomField) - if withValues { - results = append(results, hashMap[randomField]) - } - } - - return &EvalResponse{ - Result: results, - Error: nil, - } -} - // evalINCR increments the value of the specified key in args by 1, // if the key exists and the value is integer format. // The key should be the only param in args. diff --git a/internal/worker/cmd_meta.go b/internal/worker/cmd_meta.go index 1f7466ad8..25fd08739 100644 --- a/internal/worker/cmd_meta.go +++ b/internal/worker/cmd_meta.go @@ -74,11 +74,11 @@ const ( CmdPFAdd = "PFADD" CmdPFCount = "PFCOUNT" CmdPFMerge = "PFMERGE" - CmdIncr = "INCR" - CmdIncrBy = "INCRBY" - CmdDecr = "DECR" - CmdDecrBy = "DECRBY" - CmdIncrByFloat = "INCRBYFLOAT" + CmdIncr = "INCR" + CmdIncrBy = "INCRBY" + CmdDecr = "DECR" + CmdDecrBy = "DECRBY" + CmdIncrByFloat = "INCRBYFLOAT" CmdHIncrBy = "HINCRBY" CmdHIncrByFloat = "HINCRBYFLOAT" CmdHRandField = "HRANDFIELD"