Skip to content

Commit

Permalink
Add special key handling for MEMORY USAGE
Browse files Browse the repository at this point in the history
Add special handling for the MEMORY USAGE command to extract the key
from the second argument.
  • Loading branch information
woodsbury authored and Brian Picciano committed Aug 1, 2022
1 parent 248804f commit d1a6a71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ func DefaultActionProperties(cmd string, args ...string) ActionProperties {
case noKeyCmds[cmd] || len(args) == 0:
case cmd == "BITOP" && len(args) > 1:
properties.Keys = args[1:]
case cmd == "MEMORY" && len(args) > 1 && strings.ToUpper(args[0]) == "USAGE":
properties.Keys = args[1:2]
case cmd == "MSET":
properties.Keys = keysFromKeyValuePairs(args)
case cmd == "XINFO":
Expand Down
5 changes: 5 additions & 0 deletions action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func TestCmdAction(t *T) {
var dstval string
require.Nil(t, c.Do(ctx, Cmd(&dstval, "GET", key+key)))
assert.Equal(t, val, dstval)

// MEMORY USAGE needs special handling
memoryUsageCmd := Cmd(nil, "MEMORY", "USAGE", key)
assert.Equal(t, []string{key}, memoryUsageCmd.Properties().Keys)
require.Nil(t, c.Do(ctx, memoryUsageCmd))
}

func TestCmdActionMSet(t *T) {
Expand Down

0 comments on commit d1a6a71

Please sign in to comment.