Esempio n. 1
0
        private async Task <ConfigQueryResult> GetConfigValue() => await Task.Run(() =>
        {
            if (redis == null || !redis.IsConnected)
            {
                redis = ConnectionMultiplexer.Connect(_source.RedisConfig.Url);
            }

            //var manager = new RedisManagerPool(_source.RedisConfig.Url);
            var client = redis.GetDatabase();
            {
                var result = new ConfigQueryResult();

                foreach (var key in _source.RedisConfig.Keys)
                {
                    if (!client.KeyExists(key))
                    {
                        result.Exists = false;
                        return(result);
                    }

                    result.Exists = true;

                    //result.Value = client.Get<string>(key);
                    result.Value   = client.HashGetAll(key).ToStringDictionary();
                    result.Version = int.Parse(client.StringGet($"{key}{_configValueVersionPostfix}"));
                }

                return(result);
            }
        });
Esempio n. 2
0
        private bool UpdateLastVersion(ConfigQueryResult queryResult)
        {
            lock (_lastVersionLock)
            {
                if (queryResult.Version <= _lastVersion)
                {
                    return(false);
                }

                _lastVersion = queryResult.Version;
                return(true);
            }
        }
 private void LoadIntoMemory(ConfigQueryResult configQueryResult)
 {
     if (!configQueryResult.Exists)
     {
         Data.Clear();
     }
     else if (configQueryResult.Value != null)
     {
         foreach (var hashEntry in configQueryResult.Value)
         {
             if (!Data.ContainsKey(hashEntry.Key))
             {
                 Data.Add(hashEntry);
             }
         }
     }
 }