Exemple #1
0
 public RedisServiceInfo(string name, string @namespace, int databaseId, RedisServiceSettings settings)
 {
     this.Name       = name;
     this.Namespace  = @namespace;
     this.DatabaseId = databaseId;
     this.Settings   = settings;
 }
Exemple #2
0
        public RedisService(string name, RedisServiceSettings settings)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            _name     = name.Trim();
            _settings = settings ?? throw new ArgumentNullException(nameof(settings));
        }
        public RedisService(string connectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                connectionString = "127.0.0.1";
            }

            _syncRoot   = new object();
            _settings   = new RedisServiceSettings(ConfigurationOptions.Parse(connectionString));
            _subscriber = new Lazy <RedisSubscriber>(() => new RedisSubscriber(this.Redis.GetSubscriber()), true);
        }
        public RedisService(Zongsoft.Options.IOptionProvider options)
        {
            var connectionString = "127.0.0.1";

            if (options != null)
            {
                var configuration = options.GetOptionValue("/Externals/Redis") as Configuration.IRedisConfiguration;

                if (configuration != null)
                {
                    connectionString = configuration.ConnectionString;
                }
            }

            _syncRoot   = new object();
            _settings   = new RedisServiceSettings(ConfigurationOptions.Parse(connectionString));
            _subscriber = new Lazy <RedisSubscriber>(() => new RedisSubscriber(this.Redis.GetSubscriber()), true);
        }
        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;
            }));
        }
Exemple #6
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.");
            }));
        }