Uncommented AddCommand method

This commit is contained in:
Kelvin Clement Mwinuka
2024-05-26 15:26:04 +08:00
parent e3ecc42454
commit abee9ea858
5 changed files with 1459 additions and 231 deletions

View File

@@ -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) {
_, writeKeys, err := KeyExtractionFunc(command, args...)
@@ -56,25 +51,12 @@ func HandlerFunc(
}
key := writeKeys[0]
if !keyExists(ctx, key) {
_, err := createKeyAndLock(ctx, key)
if err != nil {
return nil, err
}
} else {
_, err := keyLock(ctx, key)
if err != nil {
return nil, err
}
}
defer keyUnlock(ctx, key)
value, err := strconv.ParseInt(command[2], 10, 64)
if err != nil {
return nil, err
}
err = setValue(ctx, key, value)
err = setValues(ctx, map[string]interface{}{key: value})
if err != nil {
return nil, err
}