Skip to content

Commit

Permalink
Merge pull request #1477 from DiceDB/arpit-readiness-cli-chat
Browse files Browse the repository at this point in the history
GETEX support in IronHawk
  • Loading branch information
arpitbbhayani authored Feb 11, 2025
2 parents f35a2cb + 49e63ed commit 4c3b37c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 35 deletions.
3 changes: 3 additions & 0 deletions internal/cmd/cmd_decrby.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022-present, DiceDB contributors
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information.

package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/cmd_expire.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022-present, DiceDB contributors
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information.

package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/cmd_flushdb.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022-present, DiceDB contributors
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information.

package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/cmd_getdel.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022-present, DiceDB contributors
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information.

package cmd

import (
Expand Down
41 changes: 8 additions & 33 deletions internal/cmd/cmd_getx.go → internal/cmd/cmd_getex.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strconv"
"strings"

"github.com/dicedb/dice/internal/object"
"github.com/dicedb/dice/internal/server/utils"
dstore "github.com/dicedb/dice/internal/store"
"github.com/dicedb/dicedb-go/wire"
Expand All @@ -25,18 +24,6 @@ func init() {
commandRegistry.AddCommand(cGETEX)
}

// GETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds |
// PXAT unix-time-milliseconds | PERSIST]
// Get the value of key and optionally set its expiration.
// GETEX is similar to GET, but is a write command with additional options.
// The GETEX command supports a set of options that modify its behavior:
// EX seconds -- Set the specified expire time, in seconds.
// PX milliseconds -- Set the specified expire time, in milliseconds.
// EXAT timestamp-seconds -- Set the specified Unix time at which the key will expire, in seconds.
// PXAT timestamp-milliseconds -- Set the specified Unix time at which the key will expire, in milliseconds.
// PERSIST -- Remove the time to live associated with the key.
// The RESP value of the key is encoded and then returned
// evalGET returns response.RespNIL if key is expired or it does not exist
func evalGETEX(c *Cmd, s *dstore.Store) (*CmdRes, error) {

Check failure on line 27 in internal/cmd/cmd_getex.go

View workflow job for this annotation

GitHub Actions / lint

cyclomatic complexity 41 of func `evalGETEX` is high (> 30) (gocyclo)
if len(c.C.Args) < 1 {
return cmdResNil, errWrongArgumentCount("GETEX")
Expand Down Expand Up @@ -122,37 +109,25 @@ func evalGETEX(c *Cmd, s *dstore.Store) (*CmdRes, error) {
}
}

// Get the key from the hash table
obj := s.Get(key)

if obj == nil {
existingObj := s.Get(key)
if existingObj == nil {
return cmdResNil, nil
}

if object.AssertType(obj.Type, object.ObjTypeSet) == nil ||
object.AssertType(obj.Type, object.ObjTypeJSON) == nil {
return cmdResNil, errWrongTypeOperation("GETEX")
}

// Get EvalResponse with correct data type
getResp, err := evalGET(&Cmd{
resp, err := evalGET(&Cmd{
C: &wire.Command{
Cmd: "GET",
Args: []string{key},
},
}, s)

// If there is an error return the error response
}}, s)
if err != nil {
return getResp, err
return resp, err
}

if params[PERSIST] != "" {
dstore.DelExpiry(obj, s)
dstore.DelExpiry(existingObj, s)
} else {
s.SetExpiry(obj, exDurationMs)
s.SetExpiry(existingObj, exDurationMs)
}

// return an EvalResponse with the value
return getResp, nil
return resp, nil
}
3 changes: 3 additions & 0 deletions internal/cmd/cmd_incr.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022-present, DiceDB contributors
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information.

package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/cmd_incrby.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022-present, DiceDB contributors
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information.

package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/cmd_ttl.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022-present, DiceDB contributors
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information.

package cmd

import (
Expand Down
4 changes: 2 additions & 2 deletions internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ func init() {
DiceCmds["GET"] = getCmdMeta // moved to ironhawk
DiceCmds["GETBIT"] = getBitCmdMeta
DiceCmds["GETDEL"] = getDelCmdMeta // moved to ironhawk
DiceCmds["GETEX"] = getexCmdMeta
DiceCmds["GETEX"] = getexCmdMeta // moved to ironhawk
DiceCmds["GETRANGE"] = getRangeCmdMeta
DiceCmds["GETSET"] = getSetCmdMeta
DiceCmds["HDEL"] = hdelCmdMeta
Expand Down Expand Up @@ -1452,7 +1452,7 @@ func init() {
DiceCmds["SLEEP"] = sleepCmdMeta
DiceCmds["SMEMBERS"] = smembersCmdMeta
DiceCmds["SREM"] = sremCmdMeta
DiceCmds["TTL"] = ttlCmdMeta
DiceCmds["TTL"] = ttlCmdMeta // moved to ironhawk
DiceCmds["TYPE"] = typeCmdMeta
DiceCmds["ZADD"] = zaddCmdMeta
DiceCmds["ZCOUNT"] = zcountCmdMeta
Expand Down

0 comments on commit 4c3b37c

Please sign in to comment.