mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-08 01:10:06 +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) {
|
||||
|
||||
_, 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
|
||||
}
|
||||
|
Reference in New Issue
Block a user