Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sashpawar11 committed Oct 20, 2024
1 parent 4ee440d commit 5d2b2bd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 52 deletions.
1 change: 0 additions & 1 deletion internal/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package eval

import (
"bytes"
"crypto/rand"
"errors"
"fmt"
"log/slog"
Expand Down
46 changes: 0 additions & 46 deletions internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package eval

import (
"fmt"
"crypto/rand"
"math"
"strconv"
"strings"
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions internal/worker/cmd_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5d2b2bd

Please sign in to comment.