Added embedded parameter in handleCommand method which will cause handleCommand to skip ACL auth when it's true

This commit is contained in:
Kelvin Clement Mwinuka
2024-04-21 03:48:14 +08:00
parent bef3377eff
commit fce0258e53
12 changed files with 1220 additions and 1288 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -127,7 +127,7 @@ func (server *EchoVault) ACL_CAT(category ...string) ([]string, error) {
if len(category) > 0 {
cmd = append(cmd, category[0])
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -136,7 +136,7 @@ func (server *EchoVault) ACL_CAT(category ...string) ([]string, error) {
// ACL_USERS returns a string slice containing the usernames of all the loaded users in the ACL module.
func (server *EchoVault) ACL_USERS() ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "USERS"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "USERS"}), nil, false, true)
if err != nil {
return nil, err
}
@@ -236,7 +236,7 @@ func (server *EchoVault) ACL_SETUSER(user User) (string, error) {
cmd = append(cmd, fmt.Sprintf("-&%s", channel))
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
@@ -289,7 +289,7 @@ func (server *EchoVault) ACL_SETUSER(user User) (string, error) {
//
// "user not found" - if the user requested does not exist in the ACL rules.
func (server *EchoVault) ACL_GETUSER(username string) (map[string][]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "GETUSER", username}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "GETUSER", username}), nil, false, true)
if err != nil {
return nil, err
}
@@ -326,7 +326,7 @@ func (server *EchoVault) ACL_GETUSER(username string) (map[string][]string, erro
// Returns: "OK" if the deletion is successful.
func (server *EchoVault) ACL_DELUSER(usernames ...string) (string, error) {
cmd := append([]string{"ACL", "DELUSER"}, usernames...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
@@ -335,7 +335,7 @@ func (server *EchoVault) ACL_DELUSER(usernames ...string) (string, error) {
// ACL_LIST lists all the currently loaded ACL users and their rules.
func (server *EchoVault) ACL_LIST() ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "LIST"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "LIST"}), nil, false, true)
if err != nil {
return nil, err
}
@@ -361,7 +361,7 @@ func (server *EchoVault) ACL_LOAD(options ACLLOADOptions) (string, error) {
cmd = append(cmd, "REPLACE")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
@@ -373,7 +373,7 @@ func (server *EchoVault) ACL_LOAD(options ACLLOADOptions) (string, error) {
//
// Returns: "OK" if the save is successful.
func (server *EchoVault) ACL_SAVE() (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "SAVE"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ACL", "SAVE"}), nil, false, true)
if err != nil {
return "", err
}

View File

@@ -48,7 +48,7 @@ func (server *EchoVault) COMMAND_LIST(options CommandListOptions) ([]string, err
cmd = append(cmd, []string{"FILTERBY", "MODULE", options.MODULE}...)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -60,7 +60,7 @@ func (server *EchoVault) COMMAND_LIST(options CommandListOptions) ([]string, err
//
// Returns: integer representing the count of all available commands.
func (server *EchoVault) COMMAND_COUNT() (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"COMMAND", "COUNT"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"COMMAND", "COUNT"}), nil, false, true)
if err != nil {
return 0, err
}
@@ -69,7 +69,7 @@ func (server *EchoVault) COMMAND_COUNT() (int, error) {
// SAVE triggers a new snapshot.
func (server *EchoVault) SAVE() (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SAVE"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SAVE"}), nil, false, true)
if err != nil {
return "", err
}
@@ -78,7 +78,7 @@ func (server *EchoVault) SAVE() (string, error) {
// LASTSAVE returns the unix epoch milliseconds timestamp of the last save.
func (server *EchoVault) LASTSAVE() (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LASTSAVE"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LASTSAVE"}), nil, false, true)
if err != nil {
return 0, err
}
@@ -87,7 +87,7 @@ func (server *EchoVault) LASTSAVE() (int, error) {
// REWRITEAOF triggers a compaction of the AOF file.
func (server *EchoVault) REWRITEAOF() (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"REWRITEAOF"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"REWRITEAOF"}), nil, false, true)
if err != nil {
return "", err
}

View File

@@ -109,7 +109,7 @@ func (server *EchoVault) SET(key, value string, options SETOptions) (string, err
cmd = append(cmd, "GET")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
@@ -136,7 +136,7 @@ func (server *EchoVault) MSET(kvPairs map[string]string) (string, error) {
cmd = append(cmd, []string{k, v}...)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
@@ -153,7 +153,7 @@ func (server *EchoVault) MSET(kvPairs map[string]string) (string, error) {
// Returns: A string representing the value at the specified key. If the value does not exist, an empty
// string is returned.
func (server *EchoVault) GET(key string) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"GET", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"GET", key}), nil, false, true)
if err != nil {
return "", err
}
@@ -169,7 +169,7 @@ func (server *EchoVault) GET(key string) (string, error) {
//
// Returns: a string slice of all the values.
func (server *EchoVault) MGET(keys ...string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"MGET"}, keys...)), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"MGET"}, keys...)), nil, false, true)
if err != nil {
return []string{}, err
}
@@ -184,7 +184,7 @@ func (server *EchoVault) MGET(keys ...string) ([]string, error) {
//
// Returns: The number of keys that were successfully deleted.
func (server *EchoVault) DEL(keys ...string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"DEL"}, keys...)), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(append([]string{"DEL"}, keys...)), nil, false, true)
if err != nil {
return 0, err
}
@@ -200,7 +200,7 @@ func (server *EchoVault) DEL(keys ...string) (int, error) {
//
// Returns: true if the keys is successfully persisted.
func (server *EchoVault) PERSIST(key string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PERSIST", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PERSIST", key}), nil, false, true)
if err != nil {
return false, err
}
@@ -215,7 +215,7 @@ func (server *EchoVault) PERSIST(key string) (bool, error) {
//
// Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.
func (server *EchoVault) EXPIRETIME(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"EXPIRETIME", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"EXPIRETIME", key}), nil, false, true)
if err != nil {
return 0, err
}
@@ -230,7 +230,7 @@ func (server *EchoVault) EXPIRETIME(key string) (int, error) {
//
// Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.
func (server *EchoVault) PEXPIRETIME(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PEXPIRETIME", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PEXPIRETIME", key}), nil, false, true)
if err != nil {
return 0, err
}
@@ -245,7 +245,7 @@ func (server *EchoVault) PEXPIRETIME(key string) (int, error) {
//
// Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.
func (server *EchoVault) TTL(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"TTL", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"TTL", key}), nil, false, true)
if err != nil {
return 0, err
}
@@ -260,7 +260,7 @@ func (server *EchoVault) TTL(key string) (int, error) {
//
// Returns: -2 if the keys does not exist, -1 if the key exists but has no expiry time, seconds if the key has an expiry.
func (server *EchoVault) PTTL(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PTTL", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PTTL", key}), nil, false, true)
if err != nil {
return 0, err
}
@@ -293,7 +293,7 @@ func (server *EchoVault) EXPIRE(key string, seconds int, options EXPIREOptions)
cmd = append(cmd, "GT")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -327,7 +327,7 @@ func (server *EchoVault) PEXPIRE(key string, milliseconds int, options PEXPIREOp
cmd = append(cmd, "GT")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -361,7 +361,7 @@ func (server *EchoVault) EXPIREAT(key string, unixSeconds int, options EXPIREATO
cmd = append(cmd, "GT")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -395,7 +395,7 @@ func (server *EchoVault) PEXPIREAT(key string, unixMilliseconds int, options PEX
cmd = append(cmd, "GT")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}

View File

@@ -50,7 +50,7 @@ func (server *EchoVault) HSET(key string, fieldValuePairs map[string]string) (in
cmd = append(cmd, []string{k, v}...)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -80,7 +80,7 @@ func (server *EchoVault) HSETNX(key string, fieldValuePairs map[string]string) (
cmd = append(cmd, []string{k, v}...)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -105,7 +105,7 @@ func (server *EchoVault) HSETNX(key string, fieldValuePairs map[string]string) (
func (server *EchoVault) HSTRLEN(key string, fields ...string) ([]int, error) {
cmd := append([]string{"HSTRLEN", key}, fields...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -125,7 +125,7 @@ func (server *EchoVault) HSTRLEN(key string, fields ...string) ([]int, error) {
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HVALS(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HVALS", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HVALS", key}), nil, false, true)
if err != nil {
return nil, err
}
@@ -158,7 +158,7 @@ func (server *EchoVault) HRANDFIELD(key string, options HRANDFIELDOptions) ([]st
cmd = append(cmd, "WITHVALUES")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -178,7 +178,7 @@ func (server *EchoVault) HRANDFIELD(key string, options HRANDFIELDOptions) ([]st
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HLEN(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HLEN", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HLEN", key}), nil, false, true)
if err != nil {
return 0, err
}
@@ -197,7 +197,7 @@ func (server *EchoVault) HLEN(key string) (int, error) {
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HKEYS(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HKEYS", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HKEYS", key}), nil, false, true)
if err != nil {
return nil, err
}
@@ -221,12 +221,7 @@ func (server *EchoVault) HKEYS(key string) ([]string, error) {
//
// "value at field <field> is not a number" - when the field holds a value that is not a number.
func (server *EchoVault) HINCRBY(key, field string, increment int) (float64, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"HINCRBY", key, field, strconv.Itoa(increment)}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HINCRBY", key, field, strconv.Itoa(increment)}), nil, false, true)
if err != nil {
return 0, err
}
@@ -235,12 +230,7 @@ func (server *EchoVault) HINCRBY(key, field string, increment int) (float64, err
// HINCRBYFLOAT behaves like HINCRBY but with a float increment instead of an integer increment.
func (server *EchoVault) HINCRBYFLOAT(key, field string, increment float64) (float64, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"HINCRBYFLOAT", key, field, strconv.FormatFloat(increment, 'f', -1, 64)}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HINCRBYFLOAT", key, field, strconv.FormatFloat(increment, 'f', -1, 64)}), nil, false, true)
if err != nil {
return 0, err
}
@@ -260,7 +250,7 @@ func (server *EchoVault) HINCRBYFLOAT(key, field string, increment float64) (flo
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HGETALL(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HGETALL", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HGETALL", key}), nil, false, true)
if err != nil {
return nil, err
}
@@ -281,7 +271,7 @@ func (server *EchoVault) HGETALL(key string) ([]string, error) {
//
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HEXISTS(key, field string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HEXISTS", key, field}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"HEXISTS", key, field}), nil, false, true)
if err != nil {
return false, err
}
@@ -303,7 +293,7 @@ func (server *EchoVault) HEXISTS(key, field string) (bool, error) {
// "value at <key> is not a hash" - when the provided key does not exist or is not a hash.
func (server *EchoVault) HDEL(key string, fields ...string) (int, error) {
cmd := append([]string{"HDEL", key}, fields...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}

View File

@@ -32,7 +32,7 @@ import (
//
// "LLEN command on non-list item" - when the provided key exists but is not a list.
func (server *EchoVault) LLEN(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LLEN", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LLEN", key}), nil, false, true)
fmt.Println(key, string(b), err)
if err != nil {
return 0, err
@@ -61,12 +61,7 @@ func (server *EchoVault) LLEN(key string) (int, error) {
//
// "end index must be within list range or -1" - when end index is not within the list boundaries.
func (server *EchoVault) LRANGE(key string, start, end int) ([]string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"LRANGE", key, strconv.Itoa(start), strconv.Itoa(end)}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LRANGE", key, strconv.Itoa(start), strconv.Itoa(end)}), nil, false, true)
if err != nil {
return nil, err
}
@@ -89,8 +84,7 @@ func (server *EchoVault) LRANGE(key string, start, end int) ([]string, error) {
//
// "index must be within list range" - when the index is not within the list boundary.
func (server *EchoVault) LINDEX(key string, index uint) (string, error) {
b, err := server.handleCommand(
server.context, internal.EncodeCommand([]string{"LINDEX", key, strconv.Itoa(int(index))}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LINDEX", key, strconv.Itoa(int(index))}), nil, false, true)
if err != nil {
return "", err
}
@@ -115,8 +109,7 @@ func (server *EchoVault) LINDEX(key string, index uint) (string, error) {
//
// "index must be within list range" - when the index is not within the list boundary.
func (server *EchoVault) LSET(key string, index int, value string) (string, error) {
b, err := server.handleCommand(
server.context, internal.EncodeCommand([]string{"LSET", key, strconv.Itoa(index), value}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LSET", key, strconv.Itoa(index), value}), nil, false, true)
if err != nil {
return "", err
}
@@ -126,11 +119,7 @@ func (server *EchoVault) LSET(key string, index int, value string) (string, erro
// LTRIM work similarly to LRANGE but instead of returning the new list, it replaces the original list with the
// trimmed list.
func (server *EchoVault) LTRIM(key string, start int, end int) (string, error) {
b, err := server.handleCommand(
server.context, internal.EncodeCommand([]string{"LTRIM", key, strconv.Itoa(start), strconv.Itoa(end)}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LTRIM", key, strconv.Itoa(start), strconv.Itoa(end)}), nil, false, true)
if err != nil {
return "", err
}
@@ -153,11 +142,7 @@ func (server *EchoVault) LTRIM(key string, start int, end int) (string, error) {
//
// "LREM command on non-list item" - when the provided key exists but is not a list.
func (server *EchoVault) LREM(key string, count int, value string) (string, error) {
b, err := server.handleCommand(
server.context, internal.EncodeCommand([]string{"LREM", key, strconv.Itoa(count), value}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LREM", key, strconv.Itoa(count), value}), nil, false, true)
if err != nil {
return "", err
}
@@ -186,11 +171,7 @@ func (server *EchoVault) LREM(key string, count int, value string) (string, erro
//
// "wherefrom and whereto arguments must be either LEFT or RIGHT" - if whereFrom or whereTo are not either "LEFT" or "RIGHT".
func (server *EchoVault) LMOVE(source, destination, whereFrom, whereTo string) (string, error) {
b, err := server.handleCommand(
server.context, internal.EncodeCommand([]string{"LMOVE", source, destination, whereFrom, whereTo}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LMOVE", source, destination, whereFrom, whereTo}), nil, false, true)
if err != nil {
return "", err
}
@@ -209,7 +190,7 @@ func (server *EchoVault) LMOVE(source, destination, whereFrom, whereTo string) (
//
// "LPOP command on non-list item" - when the provided key is not a list.
func (server *EchoVault) LPOP(key string) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LPOP", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"LPOP", key}), nil, false, true)
if err != nil {
return "", err
}
@@ -228,7 +209,7 @@ func (server *EchoVault) LPOP(key string) (string, error) {
//
// "RPOP command on non-list item" - when the provided key is not a list.
func (server *EchoVault) RPOP(key string) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"RPOP", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"RPOP", key}), nil, false, true)
if err != nil {
return "", err
}
@@ -251,7 +232,7 @@ func (server *EchoVault) RPOP(key string) (string, error) {
// "LPUSH command on non-list item" - when the provided key is not a list.
func (server *EchoVault) LPUSH(key string, values ...string) (string, error) {
cmd := append([]string{"LPUSH", key}, values...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
@@ -273,7 +254,7 @@ func (server *EchoVault) LPUSH(key string, values ...string) (string, error) {
// "LPUSHX command on non-list item" - when the provided key is not a list or doesn't exist.
func (server *EchoVault) LPUSHX(key string, values ...string) (string, error) {
cmd := append([]string{"LPUSHX", key}, values...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
@@ -296,7 +277,7 @@ func (server *EchoVault) LPUSHX(key string, values ...string) (string, error) {
// "RPUSH command on non-list item" - when the provided key is not a list.
func (server *EchoVault) RPUSH(key string, values ...string) (string, error) {
cmd := append([]string{"RPUSH", key}, values...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}
@@ -318,7 +299,7 @@ func (server *EchoVault) RPUSH(key string, values ...string) (string, error) {
// "RPUSHX command on non-list item" - when the provided key is not a list or doesn't exist.
func (server *EchoVault) RPUSHX(key string, values ...string) (string, error) {
cmd := append([]string{"RPUSHX", key}, values...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return "", err
}

View File

@@ -66,7 +66,7 @@ func (server *EchoVault) SUBSCRIBE(tag string, channels ...string) ReadPubSubMes
// Subscribe connection to the provided channels
cmd := append([]string{"SUBSCRIBE"}, channels...)
go func() {
_, _ = server.handleCommand(server.context, internal.EncodeCommand(cmd), connections[tag].writeConn, false)
_, _ = server.handleCommand(server.context, internal.EncodeCommand(cmd), connections[tag].writeConn, false, true)
}()
return func() []string {
@@ -99,7 +99,7 @@ func (server *EchoVault) UNSUBSCRIBE(tag string, channels ...string) {
}
cmd := append([]string{"UNSUBSCRIBE"}, channels...)
_, _ = server.handleCommand(server.context, internal.EncodeCommand(cmd), connections[tag].writeConn, false)
_, _ = server.handleCommand(server.context, internal.EncodeCommand(cmd), connections[tag].writeConn, false, true)
}
// PSUBSCRIBE subscribes the caller to the list of provided glob patterns.
@@ -132,7 +132,7 @@ func (server *EchoVault) PSUBSCRIBE(tag string, patterns ...string) ReadPubSubMe
// Subscribe connection to the provided channels
cmd := append([]string{"PSUBSCRIBE"}, patterns...)
go func() {
_, _ = server.handleCommand(server.context, internal.EncodeCommand(cmd), connections[tag].writeConn, false)
_, _ = server.handleCommand(server.context, internal.EncodeCommand(cmd), connections[tag].writeConn, false, true)
}()
return func() []string {
@@ -165,7 +165,7 @@ func (server *EchoVault) PUNSUBSCRIBE(tag string, patterns ...string) {
}
cmd := append([]string{"PUNSUBSCRIBE"}, patterns...)
_, _ = server.handleCommand(server.context, internal.EncodeCommand(cmd), connections[tag].writeConn, false)
_, _ = server.handleCommand(server.context, internal.EncodeCommand(cmd), connections[tag].writeConn, false, true)
}
// PUBLISH publishes a message to the given channel.
@@ -179,7 +179,7 @@ func (server *EchoVault) PUNSUBSCRIBE(tag string, patterns ...string) {
// Returns: "OK" when the publish is successful. This does not indicate whether each subscriber has received the message,
// only that the message has been published.
func (server *EchoVault) PUBLISH(channel, message string) (string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PUBLISH", channel, message}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PUBLISH", channel, message}), nil, false, true)
if err != nil {
return "", err
}
@@ -198,7 +198,7 @@ func (server *EchoVault) PUBSUB_CHANNELS(pattern string) ([]string, error) {
if pattern != "" {
cmd = append(cmd, pattern)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -209,7 +209,7 @@ func (server *EchoVault) PUBSUB_CHANNELS(pattern string) ([]string, error) {
//
// Returns: An integer representing the number of all the active patterns (i.e. patterns that have 1 or more subscribers).
func (server *EchoVault) PUBSUB_NUMPAT() (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PUBSUB", "NUMPAT"}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"PUBSUB", "NUMPAT"}), nil, false, true)
if err != nil {
return 0, err
}
@@ -226,7 +226,7 @@ func (server *EchoVault) PUBSUB_NUMPAT() (int, error) {
func (server *EchoVault) PUBSUB_NUMSUB(channels ...string) (map[string]int, error) {
cmd := append([]string{"PUBSUB", "NUMSUB"}, channels...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}

View File

@@ -35,7 +35,7 @@ import (
// "value at <key> is not a set" - when the provided key exists but is not a set.
func (server *EchoVault) SADD(key string, members ...string) (int, error) {
cmd := append([]string{"SADD", key}, members...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -54,7 +54,7 @@ func (server *EchoVault) SADD(key string, members ...string) (int, error) {
//
// "value at <key> is not a set" - when the provided key exists but is not a set.
func (server *EchoVault) SCARD(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SCARD", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SCARD", key}), nil, false, true)
if err != nil {
return 0, err
}
@@ -77,7 +77,7 @@ func (server *EchoVault) SCARD(key string) (int, error) {
// "key for base set <key> does not exist" - if the first key is not a set.
func (server *EchoVault) SDIFF(keys ...string) ([]string, error) {
cmd := append([]string{"SDIFF"}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -88,7 +88,7 @@ func (server *EchoVault) SDIFF(keys ...string) ([]string, error) {
// at the 'destination' key.
func (server *EchoVault) SDIFFSTORE(destination string, keys ...string) (int, error) {
cmd := append([]string{"SDIFFSTORE", destination}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -111,7 +111,7 @@ func (server *EchoVault) SDIFFSTORE(destination string, keys ...string) (int, er
// "not enough sets in the keys provided" - when only one of the provided keys is a valid set.
func (server *EchoVault) SINTER(keys ...string) ([]string, error) {
cmd := append([]string{"SINTER"}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -138,7 +138,7 @@ func (server *EchoVault) SINTERCARD(keys []string, limit uint) (int, error) {
if limit > 0 {
cmd = append(cmd, []string{"LIMIT", strconv.Itoa(int(limit))}...)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -149,7 +149,7 @@ func (server *EchoVault) SINTERCARD(keys []string, limit uint) (int, error) {
// at the 'destination' key and the cardinality of the resulting set is returned.
func (server *EchoVault) SINTERSTORE(destination string, keys ...string) (int, error) {
cmd := append([]string{"SINTERSTORE", destination}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -170,7 +170,7 @@ func (server *EchoVault) SINTERSTORE(destination string, keys ...string) (int, e
//
// "value at <key> is not a set" - when the provided key exists but is not a set.
func (server *EchoVault) SISMEMBER(key, member string) (bool, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SISMEMBER", key, member}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SISMEMBER", key, member}), nil, false, true)
if err != nil {
return false, err
}
@@ -189,7 +189,7 @@ func (server *EchoVault) SISMEMBER(key, member string) (bool, error) {
//
// "value at <key> is not a set" - when the provided key exists but is not a set.
func (server *EchoVault) SMEMBERS(key string) ([]string, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SMEMBERS", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SMEMBERS", key}), nil, false, true)
if err != nil {
return nil, err
}
@@ -212,7 +212,7 @@ func (server *EchoVault) SMEMBERS(key string) ([]string, error) {
// "value at <key> is not a set" - when the provided key exists but is not a set.
func (server *EchoVault) SMISMEMBER(key string, members ...string) ([]bool, error) {
cmd := append([]string{"SMISMEMBER", key}, members...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -239,12 +239,7 @@ func (server *EchoVault) SMISMEMBER(key string, members ...string) ([]bool, erro
//
// "destination is not a set" - when the destination key does not hold a set.
func (server *EchoVault) SMOVE(source, destination, member string) (bool, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"SMOVE", source, destination, member}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SMOVE", source, destination, member}), nil, false, true)
if err != nil {
return false, err
}
@@ -265,12 +260,7 @@ func (server *EchoVault) SMOVE(source, destination, member string) (bool, error)
//
// "value at <key> is not a set" - when the provided key exists but is not a set.
func (server *EchoVault) SPOP(key string, count uint) ([]string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"SPOP", key, strconv.Itoa(int(count))}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SPOP", key, strconv.Itoa(int(count))}), nil, false, true)
if err != nil {
return nil, err
}
@@ -292,12 +282,7 @@ func (server *EchoVault) SPOP(key string, count uint) ([]string, error) {
//
// "value at <key> is not a set" - when the provided key exists but is not a set.
func (server *EchoVault) SRANDMEMBER(key string, count int) ([]string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"SRANDMEMBER", key, strconv.Itoa(count)}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SRANDMEMBER", key, strconv.Itoa(count)}), nil, false, true)
if err != nil {
return nil, err
}
@@ -319,7 +304,7 @@ func (server *EchoVault) SRANDMEMBER(key string, count int) ([]string, error) {
// "value at <key> is not a set" - when the provided key exists but is not a set.
func (server *EchoVault) SREM(key string, members ...string) (int, error) {
cmd := append([]string{"SREM", key}, members...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -340,7 +325,7 @@ func (server *EchoVault) SREM(key string, members ...string) (int, error) {
// "value at <key> is not a set" - when the provided key exists but is not a set.
func (server *EchoVault) SUNION(keys ...string) ([]string, error) {
cmd := append([]string{"SUNION"}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -351,7 +336,7 @@ func (server *EchoVault) SUNION(keys ...string) ([]string, error) {
// set at the 'destination' key. The return value is an integer representing the cardinality of the new set.
func (server *EchoVault) SUNIONSTORE(destination string, keys ...string) (int, error) {
cmd := append([]string{"SUNIONSTORE", destination}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}

View File

@@ -184,7 +184,7 @@ func (server *EchoVault) ZADD(key string, members map[string]float64, options ZA
cmd = append(cmd, []string{strconv.FormatFloat(score, 'f', -1, 64), member}...)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -204,7 +204,7 @@ func (server *EchoVault) ZADD(key string, members map[string]float64, options ZA
//
// "value at <key> is not a sorted set" - when the provided key exists but is not a sorted set
func (server *EchoVault) ZCARD(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ZCARD", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ZCARD", key}), nil, false, true)
if err != nil {
return 0, err
}
@@ -233,7 +233,7 @@ func (server *EchoVault) ZCOUNT(key string, min, max float64) (int, error) {
strconv.FormatFloat(min, 'f', -1, 64),
strconv.FormatFloat(max, 'f', -1, 64),
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -260,7 +260,7 @@ func (server *EchoVault) ZDIFF(withscores bool, keys ...string) (map[string]floa
if withscores {
cmd = append(cmd, "WITHSCORES")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -289,7 +289,7 @@ func (server *EchoVault) ZDIFF(withscores bool, keys ...string) (map[string]floa
// "value at <key> is not a sorted set" - when a key exists but is not a sorted set.
func (server *EchoVault) ZDIFFSTORE(destination string, keys ...string) (int, error) {
cmd := append([]string{"ZDIFFSTORE", destination}, keys...)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -328,7 +328,7 @@ func (server *EchoVault) ZINTER(keys []string, options ZINTEROptions) (map[strin
cmd = append(cmd, "WITHSCORES")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -375,7 +375,7 @@ func (server *EchoVault) ZINTERSTORE(destination string, keys []string, options
cmd = append(cmd, "WITHSCORES")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -415,7 +415,7 @@ func (server *EchoVault) ZUNION(keys []string, options ZUNIONOptions) (map[strin
cmd = append(cmd, "WITHSCORES")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -462,7 +462,7 @@ func (server *EchoVault) ZUNIONSTORE(destination string, keys []string, options
cmd = append(cmd, "WITHSCORES")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -488,7 +488,7 @@ func (server *EchoVault) ZUNIONSTORE(destination string, keys []string, options
// "value at <key> is not a sorted set" - when a key exists but is not a sorted set.
func (server *EchoVault) ZINCRBY(key string, increment float64, member string) (float64, error) {
cmd := []string{"ZINCRBY", key, strconv.FormatFloat(increment, 'f', -1, 64), member}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -532,7 +532,7 @@ func (server *EchoVault) ZMPOP(keys []string, options ZMPOPOptions) ([][]string,
cmd = append(cmd, []string{"COUNT", strconv.Itoa(1)}...)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -561,7 +561,7 @@ func (server *EchoVault) ZMSCORE(key string, members ...string) ([]interface{},
cmd = append(cmd, member)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -606,7 +606,7 @@ func (server *EchoVault) ZMSCORE(key string, members ...string) ([]interface{},
// "value at <key> is not a sorted set" - when the provided key exists but is not a sorted set
func (server *EchoVault) ZLEXCOUNT(key, min, max string) (int, error) {
cmd := []string{"ZLEXCOUNT", key, min, max}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -630,12 +630,7 @@ func (server *EchoVault) ZLEXCOUNT(key, min, max string) (int, error) {
//
// "value at <key> is not a sorted set" - when a key exists but is not a sorted set.
func (server *EchoVault) ZPOPMAX(key string, count uint) ([][]string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"ZPOPMAX", key, strconv.Itoa(int(count))}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ZPOPMAX", key, strconv.Itoa(int(count))}), nil, false, true)
if err != nil {
return nil, err
}
@@ -659,12 +654,7 @@ func (server *EchoVault) ZPOPMAX(key string, count uint) ([][]string, error) {
//
// "value at <key> is not a sorted set" - when a key exists but is not a sorted set.
func (server *EchoVault) ZPOPMIN(key string, count uint) ([][]string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"ZPOPMIN", key, strconv.Itoa(int(count))}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"ZPOPMIN", key, strconv.Itoa(int(count))}), nil, false, true)
if err != nil {
return nil, err
}
@@ -701,7 +691,7 @@ func (server *EchoVault) ZRANDMEMBER(key string, count int, withscores bool) ([]
cmd = append(cmd, "WITHSCORES")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -733,7 +723,7 @@ func (server *EchoVault) ZRANK(key string, member string, withscores bool) (map[
cmd = append(cmd, "WITHSCORES")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -770,7 +760,7 @@ func (server *EchoVault) ZREVRANK(key string, member string, withscores bool) (m
cmd = append(cmd, "WITHSCORES")
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -796,7 +786,7 @@ func (server *EchoVault) ZREVRANK(key string, member string, withscores bool) (m
// "value at <key> is not a sorted set" - when a key exists but is not a sorted set.
func (server *EchoVault) ZSCORE(key string, member string) (interface{}, error) {
cmd := []string{"ZSCORE", key, member}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -836,7 +826,7 @@ func (server *EchoVault) ZREM(key string, members ...string) (int, error) {
for _, member := range members {
cmd = append(cmd, member)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -866,7 +856,7 @@ func (server *EchoVault) ZREMRANGEBYSCORE(key string, min float64, max float64)
strconv.FormatFloat(max, 'f', -1, 64),
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
@@ -911,7 +901,7 @@ func (server *EchoVault) ZRANGE(key, start, stop string, options ZRANGEOptions)
cmd = append(cmd, []string{"LIMIT", strconv.Itoa(int(options.Offset)), strconv.Itoa(int(options.Count))}...)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return nil, err
}
@@ -959,7 +949,7 @@ func (server *EchoVault) ZRANGESTORE(destination, source, start, stop string, op
cmd = append(cmd, []string{"LIMIT", strconv.Itoa(int(options.Offset)), strconv.Itoa(int(options.Count))}...)
}
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}

View File

@@ -28,12 +28,7 @@ import (
//
// - "value at key <key> is not a string" when the key provided does not hold a string.
func (server *EchoVault) SETRANGE(key string, offset int, new string) (int, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"SETRANGE", key, strconv.Itoa(offset), new}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SETRANGE", key, strconv.Itoa(offset), new}), nil, false, true)
if err != nil {
return 0, err
}
@@ -48,7 +43,7 @@ func (server *EchoVault) SETRANGE(key string, offset int, new string) (int, erro
//
// - "value at key <key> is not a string" - when the value at the keys is not a string.
func (server *EchoVault) STRLEN(key string) (int, error) {
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"STRLEN", key}), nil, false)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"STRLEN", key}), nil, false, true)
if err != nil {
return 0, err
}
@@ -66,12 +61,7 @@ func (server *EchoVault) STRLEN(key string) (int, error) {
//
// - "value at key <key> is not a string" - when the value at the keys is not a string.
func (server *EchoVault) SUBSTR(key string, start, end int) (string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"SUBSTR", key, strconv.Itoa(start), strconv.Itoa(end)}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"SUBSTR", key, strconv.Itoa(start), strconv.Itoa(end)}), nil, false, true)
if err != nil {
return "", err
}
@@ -80,12 +70,7 @@ func (server *EchoVault) SUBSTR(key string, start, end int) (string, error) {
// GETRANGE works the same as SUBSTR.
func (server *EchoVault) GETRANGE(key string, start, end int) (string, error) {
b, err := server.handleCommand(
server.context,
internal.EncodeCommand([]string{"GETRANGE", key, strconv.Itoa(start), strconv.Itoa(end)}),
nil,
false,
)
b, err := server.handleCommand(server.context, internal.EncodeCommand([]string{"GETRANGE", key, strconv.Itoa(start), strconv.Itoa(end)}), nil, false, true)
if err != nil {
return "", err
}

View File

@@ -236,7 +236,7 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
echovault.KeyUnlock(ctx, key)
}),
aof.WithHandleCommandFunc(func(command []byte) {
_, err := echovault.handleCommand(context.Background(), command, nil, true)
_, err := echovault.handleCommand(context.Background(), command, nil, true, false)
if err != nil {
log.Println(err)
}
@@ -391,7 +391,7 @@ func (server *EchoVault) handleConnection(conn net.Conn) {
break
}
res, err := server.handleCommand(ctx, message, &conn, false)
res, err := server.handleCommand(ctx, message, &conn, false, false)
if err != nil && errors.Is(err, io.EOF) {
break

View File

@@ -46,7 +46,7 @@ func (server *EchoVault) getCommand(cmd string) (types.Command, error) {
return types.Command{}, fmt.Errorf("command %s not supported", cmd)
}
func (server *EchoVault) handleCommand(ctx context.Context, message []byte, conn *net.Conn, replay bool) ([]byte, error) {
func (server *EchoVault) handleCommand(ctx context.Context, message []byte, conn *net.Conn, replay bool, embedded bool) ([]byte, error) {
cmd, err := internal.Decode(message)
if err != nil {
return nil, err
@@ -66,8 +66,9 @@ func (server *EchoVault) handleCommand(ctx context.Context, message []byte, conn
handler = subCommand.HandlerFunc
}
if conn != nil && server.acl != nil {
if conn != nil && server.acl != nil && !embedded {
// Authorize connection if it's provided and if ACL module is present
// and the embedded parameter is false.
if err = server.acl.AuthorizeConnection(conn, cmd, command, subCommand); err != nil {
return nil, err
}