Skip to content

Commit

Permalink
rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
ayadav16 committed Sep 26, 2024
1 parent ebabd5c commit c547531
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
2 changes: 1 addition & 1 deletion internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type DiceCmdMeta struct {
Eval func([]string, *dstore.Store) []byte
Arity int // number of arguments, it is possible to use -N to say >= N
KeySpecs
SubCommands []string // list of sub-commands supported by the commmand
SubCommands []string // list of sub-commands supported by the command

// IsMigrated indicates whether a command has been migrated to a new evaluation
// mechanism. If true, the command uses the newer evaluation logic represented by
Expand Down
60 changes: 30 additions & 30 deletions internal/eval/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ const (
XOR string = "XOR"
NOT string = "NOT"

Ex string = "EX"
Px string = "PX"
Pxat string = "PXAT"
Exat string = "EXAT"
XX string = "XX"
NX string = "NX"
Xx string = "xx"
Nx string = "nx"
GT string = "GT"
LT string = "LT"
KEEPTTL string = "KEEPTTL"
Keepttl string = "keepttl"
Sync string = "SYNC"
Async string = "ASYNC"
Help string = "HELP"
Memory string = "MEMORY"
Count string = "COUNT"
GetKeys string = "GETKEYS"
List string = "LIST"
Info string = "INFO"
Null string = "null"
null string = "null"
NULL string = "null"
Ex string = "EX"
Px string = "PX"
Pxat string = "PXAT"
Exat string = "EXAT"
XX string = "XX"
NX string = "NX"
Xx string = "xx"
Nx string = "nx"
GT string = "GT"
LT string = "LT"
KEEPTTL string = "KEEPTTL"
Keepttl string = "keepttl"
Sync string = "SYNC"
Async string = "ASYNC"
Help string = "HELP"
Memory string = "MEMORY"
Count string = "COUNT"
GetKeys string = "GETKEYS"
List string = "LIST"
Info string = "INFO"
Null string = "null"
null string = "null"
NULL string = "null"
WITHVALUES string = "WITHVALUES"
GET string = "GET"
SET string = "SET"
INCRBY string = "INCRBY"
OVERFLOW string = "OVERFLOW"
WRAP string = "WRAP"
SAT string = "SAT"
FAIL string = "FAIL"
GET string = "GET"
SET string = "SET"
INCRBY string = "INCRBY"
OVERFLOW string = "OVERFLOW"
WRAP string = "WRAP"
SAT string = "SAT"
FAIL string = "FAIL"
)
18 changes: 16 additions & 2 deletions internal/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -4181,7 +4181,7 @@ func evalHRANDFIELD(args []string, store *dstore.Store) []byte {

// The third argument is the "WITHVALUES" option.
if len(args) == 3 {
if strings.ToUpper(args[2]) != WITHVALUES {
if !strings.EqualFold(args[2], WITHVALUES) {
return diceerrors.NewErrWithFormattedMessage(diceerrors.SyntaxErr)
}
withValues = true
Expand Down Expand Up @@ -4233,10 +4233,11 @@ func selectRandomFields(hashMap HashMap, count int, withValues bool) []byte {
return clientio.Encode(results, false)
}

// parseEncodingAndOffet function parses offset and encoding type for bitfield commands
// as this part is common to all subcommands
func parseEncodingAndOffset(args []string) (eType interface{}, eVal interface{}, offset interface{}, err error) {

Check failure on line 4238 in internal/eval/eval.go

View workflow job for this annotation

GitHub Actions / lint

paramTypeCombine: func(args []string) (eType interface{}, eVal interface{}, offset interface{}, err error) could be replaced with func(args []string) (eType, eVal, offset interface{}, err error) (gocritic)
encodingRaw := args[0]
offsetRaw := args[1]

switch encodingRaw[0] {
case 'i':
eType = "SIGNED"

Check failure on line 4243 in internal/eval/eval.go

View workflow job for this annotation

GitHub Actions / lint

string `SIGNED` has 4 occurrences, make it a constant (goconst)
Expand Down Expand Up @@ -4282,6 +4283,19 @@ func parseEncodingAndOffset(args []string) (eType interface{}, eVal interface{},
}
return
}

// evalBITFIELD evaluates BITFIELD operations on a key store string, int or bytearray types
// it returns an array of results depending on the subcommands
// it allows mutation using SET and INCRBY commands
// returns arity error, offset type error, overflow type error, encoding type error, integer error, syntax error
// GET <encoding> <offset> -- Returns the specified bit field.
// SET <encoding> <offset> <value> -- Set the specified bit field
// and returns its old value.
// INCRBY <encoding> <offset> <increment> -- Increments or decrements
// (if a negative increment is given) the specified bit field and returns the new value.
// There is another subcommand that only changes the behavior of successive
// INCRBY and SET subcommands calls by setting the overflow behavior:
// OVERFLOW [WRAP|SAT|FAIL]`
func evalBITFIELD(args []string, store *dstore.Store) []byte {
if len(args) < 1 {
return diceerrors.NewErrArity("BITFIELD")
Expand Down
3 changes: 0 additions & 3 deletions internal/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ import (
"github.com/ohler55/ojg/jp"

"github.com/axiomhq/hyperloglog"
"github.com/bytedance/sonic"
"github.com/dicedb/dice/internal/clientio"
diceerrors "github.com/dicedb/dice/internal/errors"
"github.com/dicedb/dice/internal/object"
"github.com/dicedb/dice/internal/server/utils"
dstore "github.com/dicedb/dice/internal/store"
"github.com/ohler55/ojg/jp"
testifyAssert "github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
)
Expand Down

0 comments on commit c547531

Please sign in to comment.