mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-05 16:06:57 +08:00
Renamed *AccessKey type to better represent the response on *KeyExtractionFunc types
This commit is contained in:
@@ -22,42 +22,42 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func zaddKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zaddKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 4 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: make([]string, 0),
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zcardKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zcardKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) != 2 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zcountKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zcountKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) != 4 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:2],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zdiffKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zdiffKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 2 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
|
||||
withscoresIndex := slices.IndexFunc(cmd, func(s string) bool {
|
||||
@@ -65,45 +65,45 @@ func zdiffKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
})
|
||||
|
||||
if withscoresIndex == -1 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:withscoresIndex],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zdiffstoreKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zdiffstoreKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 3 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[2:],
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zincrbyKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zincrbyKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) != 4 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: make([]string, 0),
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zinterKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zinterKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 2 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
endIdx := slices.IndexFunc(cmd[1:], func(s string) bool {
|
||||
if strings.EqualFold(s, "WEIGHTS") ||
|
||||
@@ -114,25 +114,25 @@ func zinterKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
return false
|
||||
})
|
||||
if endIdx == -1 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
if endIdx >= 1 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:endIdx],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
|
||||
func zinterstoreKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zinterstoreKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 3 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
endIdx := slices.IndexFunc(cmd[1:], func(s string) bool {
|
||||
if strings.EqualFold(s, "WEIGHTS") ||
|
||||
@@ -143,192 +143,192 @@ func zinterstoreKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
return false
|
||||
})
|
||||
if endIdx == -1 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[2:],
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
if endIdx >= 3 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[2:endIdx],
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
|
||||
func zmpopKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zmpopKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 2 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
endIdx := slices.IndexFunc(cmd, func(s string) bool {
|
||||
return slices.Contains([]string{"MIN", "MAX", "COUNT"}, strings.ToUpper(s))
|
||||
})
|
||||
if endIdx == -1 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: make([]string, 0),
|
||||
WriteKeys: cmd[1:],
|
||||
}, nil
|
||||
}
|
||||
if endIdx >= 2 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: make([]string, 0),
|
||||
WriteKeys: cmd[1:endIdx],
|
||||
}, nil
|
||||
}
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
|
||||
func zmscoreKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zmscoreKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 3 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:2],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zpopKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zpopKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 2 || len(cmd) > 3 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: make([]string, 0),
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zrandmemberKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zrandmemberKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 2 || len(cmd) > 4 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:2],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zrankKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zrankKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 3 || len(cmd) > 4 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:2],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zremKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zremKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 3 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: make([]string, 0),
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zrevrankKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zrevrankKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 3 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:2],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zscoreKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zscoreKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) != 3 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:2],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zremrangebylexKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zremrangebylexKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) != 4 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: make([]string, 0),
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zremrangebyrankKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zremrangebyrankKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) != 4 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: make([]string, 0),
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zremrangebyscoreKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zremrangebyscoreKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) != 4 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: make([]string, 0),
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zlexcountKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zlexcountKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) != 4 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:2],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zrangeKeyCount(cmd []string) (internal.AccessKeys, error) {
|
||||
func zrangeKeyCount(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 4 || len(cmd) > 10 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:2],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zrangeStoreKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zrangeStoreKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 5 || len(cmd) > 11 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[2:3],
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func zunionKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zunionKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 2 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
endIdx := slices.IndexFunc(cmd[1:], func(s string) bool {
|
||||
if strings.EqualFold(s, "WEIGHTS") ||
|
||||
@@ -339,25 +339,25 @@ func zunionKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
return false
|
||||
})
|
||||
if endIdx == -1 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:],
|
||||
WriteKeys: make([]string, 0),
|
||||
}, nil
|
||||
}
|
||||
if endIdx >= 1 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[1:endIdx],
|
||||
WriteKeys: cmd[1:endIdx],
|
||||
}, nil
|
||||
}
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
|
||||
func zunionstoreKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
func zunionstoreKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
|
||||
if len(cmd) < 3 {
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
endIdx := slices.IndexFunc(cmd[1:], func(s string) bool {
|
||||
if strings.EqualFold(s, "WEIGHTS") ||
|
||||
@@ -368,18 +368,18 @@ func zunionstoreKeyFunc(cmd []string) (internal.AccessKeys, error) {
|
||||
return false
|
||||
})
|
||||
if endIdx == -1 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[2:],
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
if endIdx >= 1 {
|
||||
return internal.AccessKeys{
|
||||
return internal.KeyExtractionFuncResult{
|
||||
Channels: make([]string, 0),
|
||||
ReadKeys: cmd[2:endIdx],
|
||||
WriteKeys: cmd[1:2],
|
||||
}, nil
|
||||
}
|
||||
return internal.AccessKeys{}, errors.New(constants.WrongArgsResponse)
|
||||
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
|
Reference in New Issue
Block a user