config

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package config defines a series of devspore redis configuration, include configuration from yaml and remote etcd.

Index

Constants

View Source
const (
	ServerTypeCluster     = "cluster"
	ServerTypeNormal      = "normal"
	ServerTypeMasterSlave = "master-slave"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncRemotePoolConfiguration added in v1.0.0

type AsyncRemotePoolConfiguration struct {
	Persist         bool   `yaml:"persist"`
	ThreadCoreSize  int    `yaml:"threadCoreSize"`
	MaximumPoolSize int    `yaml:"maximumPoolSize"`
	KeepAliveTime   int64  `yaml:"keepAliveTime"`
	TaskQueueSize   int    `yaml:"taskQueueSize"`
	PersistDir      string `yaml:"persistDir"`
}

type AsyncRemoteWrite added in v1.0.0

type AsyncRemoteWrite struct {
	RetryTimes int `yaml:"retryTimes"`
}

type Configuration

type Configuration struct {
	Props          *mas.PropertiesConfiguration `yaml:"props"`
	EtcdConfig     *etcd.EtcdConfiguration      `yaml:"etcd"`
	RedisConfig    *RedisConfiguration          `yaml:"redis"`
	RouteAlgorithm string                       `yaml:"routeAlgorithm"`
	Active         string                       `yaml:"active"`
	Chaos          *mas.InjectionProperties     `yaml:"chaos"`
}

Configuration is used to create DevsporeClient

func LoadConfiguration

func LoadConfiguration(yamlFilePath string) (*Configuration, error)

LoadConfiguration generate Configuration form yaml configuration file.

func (*Configuration) AssignRemoteConfig

func (c *Configuration) AssignRemoteConfig()

AssignRemoteConfig will combine local configuration and remote configuration.

func (*Configuration) ComputeNearestServer

func (c *Configuration) ComputeNearestServer()

ComputeNearestServer compute nearest redis server according to server's cloud, region and az.

func (*Configuration) ConvertServerConfiguration

func (c *Configuration) ConvertServerConfiguration()

ConvertServerConfiguration convert devspore server configuration to go-redis Options or cluster Options.

func (*Configuration) OnChanged

func (c *Configuration) OnChanged(active string)

OnChanged when remote etcd active key changed, change the Configuration's active server.

type Listener

type Listener interface {
	OnChanged(active string)
}

Listener is the interface for watching etcd active key changes.

type RedisConfiguration

type RedisConfiguration struct {
	RedisGroupName               string                            `yaml:"redisGroupName"`
	UserName                     string                            `yaml:"useName"`
	Nearest                      string                            `yaml:"nearest"`
	Servers                      map[string]*ServerConfiguration   `yaml:"servers"`
	ConnectionPoolConfig         *RedisConnectionPoolConfiguration `yaml:"connectionPool"`
	AsyncRemoteWrite             *AsyncRemoteWrite                 `yaml:"asyncRemoteWrite"`
	AsyncRemotePoolConfiguration *AsyncRemotePoolConfiguration     `yaml:"asyncRemotePool"`
}

RedisConfiguration defines a series of redis configuration in yaml file.

type RedisConnectionPoolConfiguration

type RedisConnectionPoolConfiguration struct {
	Enable bool `yaml:"enable"`
}

type RemoteConfigurationLoader

type RemoteConfigurationLoader struct {
	// contains filtered or unexported fields
}

RemoteConfigurationLoader to load remote configuration from etcd

func NewRemoteConfigurationLoader

func NewRemoteConfigurationLoader(props *mas.PropertiesConfiguration,
	etcdConfiguration *etcd.EtcdConfiguration) *RemoteConfigurationLoader

NewRemoteConfigurationLoader create a loader to load remote configuration

func (*RemoteConfigurationLoader) AddRouterListener

func (l *RemoteConfigurationLoader) AddRouterListener(listener Listener)

AddRouterListener add a listener

func (*RemoteConfigurationLoader) GetConfiguration

func (l *RemoteConfigurationLoader) GetConfiguration() *RemoteRedisConfiguration

GetConfiguration from etcd, which contains route algorithm, active server and all redis servers.

func (*RemoteConfigurationLoader) Init

func (l *RemoteConfigurationLoader) Init()

Init etcd start watch activeKey

type RemoteRedisConfiguration

type RemoteRedisConfiguration struct {
	RouteAlgorithm string
	Active         string
	Servers        map[string]*ServerConfiguration
}

RemoteRedisConfiguration is set in remote etcd, contains active server, routeAlgorithm and redis servers.

func NewRemoteRedisConfiguration

func NewRemoteRedisConfiguration(routeAlgorithm, active, serversStr string) *RemoteRedisConfiguration

NewRemoteRedisConfiguration create a RemoteRedisConfiguration with etcd configuration strings .

type ServerConfiguration

type ServerConfiguration struct {
	Hosts          string                             `yaml:"hosts"`
	Password       string                             `yaml:"password"`
	Type           string                             `yaml:"type"` // cluster, normal, master-slave
	Cloud          string                             `yaml:"cloud"`
	Region         string                             `yaml:"region"`
	Azs            string                             `yaml:"azs"`
	ConnectionPool *ServerConnectionPoolConfiguration `yaml:"pool"`
	ClusterOptions *redis.ClusterOptions
	Options        *redis.Options
}

ServerConfiguration contains yaml redis server configuration, go-redis Options and ClusterOptions(when type is cluster).

type ServerConnectionPoolConfiguration

type ServerConnectionPoolConfiguration struct {
	MaxTotal                      int `yaml:"maxTotal"`
	MaxIdle                       int `yaml:"maxIdle"`
	MinIdle                       int `yaml:"minIdle"`
	MaxWaitMillis                 int `yaml:"maxWaitMillis"`
	TimeBetweenEvictionRunsMillis int `yaml:"timeBetweenEvictionRunsMillis"`
}

ServerConnectionPoolConfiguration connection pool configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL