コード例 #1
0
ファイル: RedisClient.cs プロジェクト: yonglehou/Symbiote
        public bool HSet <T>(string key, string field, T value)
        {
            ValidateKeyVal(key);
            ValidateFieldVal(field);
            ValidateInputValueNotDefault(value);
            var command = new HSetCommand <T>(key, field, value);

            return(command.Execute());
        }
コード例 #2
0
        private string PerformHSet(HSetCommand command)
        {
            if (_storage.TryGetValue(command.Key, out var value))
            {
                if (value is HashValue hv)
                {
                    if (hv.Value.ContainsKey(command.Field))
                    {
                        return($"Hash map associated with key {command.Key} already have key {command.Field} ");
                    }
                    hv.Value.TryAdd(command.Field, command.Value);
                    return($"{command.Field} {command.Value} pair has been added to hash map associated with key {command.Key}");
                }

                return($"Type associated with key {command.Key} is not a hash-value type");
            }
            var newValue = new HashValue
            {
                Value = { [command.Field] = command.Value }
            };

            _storage[command.Key] = newValue;
            return($"{command.Field} {command.Value} pair has been added to hash map associated with key {command.Key}");
        }