mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-17 21:41:41 +08:00
Uncommented AddCommand method
This commit is contained in:
@@ -40,14 +40,9 @@ func KeyExtractionFunc(cmd []string, args ...string) ([]string, []string, error)
|
||||
func HandlerFunc(
|
||||
ctx context.Context,
|
||||
command []string,
|
||||
keyExists func(ctx context.Context, key string) bool,
|
||||
keyLock func(ctx context.Context, key string) (bool, error),
|
||||
keyUnlock func(ctx context.Context, key string),
|
||||
keyRLock func(ctx context.Context, key string) (bool, error),
|
||||
keyRUnlock func(ctx context.Context, key string),
|
||||
createKeyAndLock func(ctx context.Context, key string) (bool, error),
|
||||
getValue func(ctx context.Context, key string) interface{},
|
||||
setValue func(ctx context.Context, key string, value interface{}) error,
|
||||
keysExist func(keys []string) map[string]bool,
|
||||
getValues func(ctx context.Context, keys []string) map[string]interface{},
|
||||
setValues func(ctx context.Context, entries map[string]interface{}) error,
|
||||
args ...string) ([]byte, error) {
|
||||
|
||||
readKeys, _, err := KeyExtractionFunc(command, args...)
|
||||
@@ -55,18 +50,13 @@ func HandlerFunc(
|
||||
return nil, err
|
||||
}
|
||||
key := readKeys[0]
|
||||
exists := keysExist(readKeys)[key]
|
||||
|
||||
if !keyExists(ctx, key) {
|
||||
if !exists {
|
||||
return []byte(":0\r\n"), nil
|
||||
}
|
||||
|
||||
_, err = keyRLock(ctx, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer keyRUnlock(ctx, key)
|
||||
|
||||
val, ok := getValue(ctx, key).(int64)
|
||||
val, ok := getValues(ctx, []string{key})[key].(int64)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("value at key %s is not an integer", key)
|
||||
}
|
||||
|
Reference in New Issue
Block a user