-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of ssh://github.com/absolutelightning/treds
- Loading branch information
Showing
9 changed files
with
537 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"regexp" | ||
"strconv" | ||
|
||
"treds/resp" | ||
"treds/store" | ||
) | ||
|
||
const KeysHCommand = "KEYSH" | ||
|
||
func RegisterKeysHCommand(r CommandRegistry) { | ||
r.Add(&CommandRegistration{ | ||
Name: KeysHCommand, | ||
Validate: validateKeysH(), | ||
Execute: executeKeysH(), | ||
}) | ||
} | ||
|
||
func validateKeysH() ValidationHook { | ||
return func(args []string) error { | ||
if len(args) < 2 { | ||
return fmt.Errorf("expected minimum 2 argument, got %d", len(args)) | ||
} | ||
if len(args) == 3 { | ||
_, err := strconv.Atoi(args[2]) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
_, err := regexp.Compile(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func executeKeysH() ExecutionHook { | ||
return func(args []string, store store.Store) string { | ||
regex := "" | ||
count := math.MaxInt64 | ||
if len(args) >= 2 { | ||
regex = args[1] | ||
} | ||
if len(args) == 3 { | ||
count, _ = strconv.Atoi(args[2]) | ||
} | ||
v, err := store.KeysH(args[0], regex, count) | ||
if err != nil { | ||
return resp.EncodeError(err.Error()) | ||
} | ||
return resp.EncodeStringArray(v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"regexp" | ||
"strconv" | ||
|
||
"treds/resp" | ||
"treds/store" | ||
) | ||
|
||
const KeysLCommand = "KEYSL" | ||
|
||
func RegisterKeysLCommand(r CommandRegistry) { | ||
r.Add(&CommandRegistration{ | ||
Name: KeysLCommand, | ||
Validate: validateKeysL(), | ||
Execute: executeKeysL(), | ||
}) | ||
} | ||
|
||
func validateKeysL() ValidationHook { | ||
return func(args []string) error { | ||
if len(args) < 2 { | ||
return fmt.Errorf("expected minimum 2 argument, got %d", len(args)) | ||
} | ||
if len(args) == 3 { | ||
_, err := strconv.Atoi(args[2]) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
_, err := regexp.Compile(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func executeKeysL() ExecutionHook { | ||
return func(args []string, store store.Store) string { | ||
regex := "" | ||
count := math.MaxInt64 | ||
if len(args) >= 2 { | ||
regex = args[1] | ||
} | ||
if len(args) == 3 { | ||
count, _ = strconv.Atoi(args[2]) | ||
} | ||
v, err := store.KeysL(args[0], regex, count) | ||
if err != nil { | ||
return resp.EncodeError(err.Error()) | ||
} | ||
return resp.EncodeStringArray(v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"regexp" | ||
"strconv" | ||
|
||
"treds/resp" | ||
"treds/store" | ||
) | ||
|
||
const KeysSCommand = "KEYSS" | ||
|
||
func RegisterKeysSCommand(r CommandRegistry) { | ||
r.Add(&CommandRegistration{ | ||
Name: KeysSCommand, | ||
Validate: validateKeysS(), | ||
Execute: executeKeysS(), | ||
}) | ||
} | ||
|
||
func validateKeysS() ValidationHook { | ||
return func(args []string) error { | ||
if len(args) < 2 { | ||
return fmt.Errorf("expected minimum 2 argument, got %d", len(args)) | ||
} | ||
if len(args) == 3 { | ||
_, err := strconv.Atoi(args[2]) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
_, err := regexp.Compile(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func executeKeysS() ExecutionHook { | ||
return func(args []string, store store.Store) string { | ||
regex := "" | ||
count := math.MaxInt64 | ||
if len(args) >= 2 { | ||
regex = args[1] | ||
} | ||
if len(args) == 3 { | ||
count, _ = strconv.Atoi(args[2]) | ||
} | ||
v, err := store.KeysS(args[0], regex, count) | ||
if err != nil { | ||
return resp.EncodeError(err.Error()) | ||
} | ||
return resp.EncodeStringArray(v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"regexp" | ||
"strconv" | ||
|
||
"treds/resp" | ||
"treds/store" | ||
) | ||
|
||
const KeysZCommand = "KEYSZ" | ||
|
||
func RegisterKeysZCommand(r CommandRegistry) { | ||
r.Add(&CommandRegistration{ | ||
Name: KeysZCommand, | ||
Validate: validateKeysZ(), | ||
Execute: executeKeysZ(), | ||
}) | ||
} | ||
|
||
func validateKeysZ() ValidationHook { | ||
return func(args []string) error { | ||
if len(args) < 2 { | ||
return fmt.Errorf("expected minimum 2 argument, got %d", len(args)) | ||
} | ||
if len(args) == 3 { | ||
_, err := strconv.Atoi(args[2]) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
_, err := regexp.Compile(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func executeKeysZ() ExecutionHook { | ||
return func(args []string, store store.Store) string { | ||
regex := "" | ||
count := math.MaxInt64 | ||
if len(args) >= 2 { | ||
regex = args[1] | ||
} | ||
if len(args) == 3 { | ||
count, _ = strconv.Atoi(args[2]) | ||
} | ||
v, err := store.KeysZ(args[0], regex, count) | ||
if err != nil { | ||
return resp.EncodeError(err.Error()) | ||
} | ||
return resp.EncodeStringArray(v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.