コード例 #1
0
        public RedisService GetRedis(string name)
        {
            return(_services.GetOrAdd(name ?? string.Empty, key =>
            {
                var settings = ApplicationContext.Current.Configuration.GetOption <ConnectionSettingCollection>("/Externals/Redis/ConnectionSettings");

                if (settings != null)
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        key = settings.Default ?? string.Empty;
                    }

                    if (settings.TryGet(key, out var setting))
                    {
                        return new RedisService(key, RedisServiceSettings.Parse(setting.Value));
                    }
                }

                return null;
            }));
        }
コード例 #2
0
        public RedisService GetRedis(string name)
        {
            return(_services.GetOrAdd(name ?? string.Empty, key =>
            {
                var settings = ApplicationContext.Current.Configuration.GetOption <ConnectionSettingCollection>("/Externals/Redis/ConnectionSettings");

                if (settings != null)
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        key = settings.Default ?? string.Empty;
                    }

                    if (settings.TryGet(key, out var setting))
                    {
                        return new RedisService(key, RedisServiceSettings.Parse(setting.Value));
                    }
                }

                throw new KeyNotFoundException($"The Redis service with the specified name '{key}' is undefined.");
            }));
        }