예제 #1
0
        public WriteResult Delete(string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return(WriteResult.Failure("Key parameter is missing"));
            }

            string value;
            var    isSuccess = storage.TryRemove(key, out value);

            return(isSuccess
                ? WriteResult.Success($"Key '{key}' with value '{value}' removed")
                : WriteResult.Success($"Key '{key}' doesn't exist"));
        }
예제 #2
0
        public WriteResult Insert(string key, string value)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return(WriteResult.Failure("Key parameter is missing"));
            }

            if (string.IsNullOrWhiteSpace(value))
            {
                return(WriteResult.Failure("Value parameter is missing"));
            }

            var isSuccess = storage.TryAdd(key, value);

            return(isSuccess
                ? WriteResult.Success($"Key '{key}' with value '{value}' added")
                : WriteResult.Failure($"Key '{key}' already exists"));
        }
예제 #3
0
        public WriteResult Update(string key, string value)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return(WriteResult.Failure("Key parameter is missing"));
            }

            if (string.IsNullOrWhiteSpace(value))
            {
                return(WriteResult.Failure("Value parameter is missing"));
            }

            var oldValue = Find <string>(key);

            if (oldValue.IsSuccess)
            {
                var isSuccess = storage.TryUpdate(key, value, oldValue.Value);
                return(WriteResult.Success($"Value '{oldValue.Value}' with '{key}' updated with new value '{value}'"));
            }
            else
            {
                return(WriteResult.Failure(oldValue.Message));
            }
        }