Documentation ¶
Index ¶
- func InitDefaultPool(config *DialConfig) (*redis.Pool, error)
- func InitMultiPools(configs []*MultiDialConfig) error
- func InitPool(name string, config *DialConfig) (*redis.Pool, error)
- func NewPool(config *DialConfig) (*redis.Pool, error)
- func Pool(name ...string) (*redis.Pool, error)
- func RegisterPool(name string, pool *redis.Pool)
- func UseAsDefaultPool(name string)
- type DialConfig
- type Lock
- type MultiDialConfig
- type Options
- type Subscription
- type SubscriptionProcessor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitDefaultPool ¶
func InitDefaultPool(config *DialConfig) (*redis.Pool, error)
InitDefaultPool
Init redis connection pool with `defaultPoolName` value, so can fetch it again directly through `iRedis.Pool()` without parameter.
Only can access it by `defaultPoolName` value, after this func called, UseAsDefaultPool no longer takes effect. And NOT SUGGEST to use it with `UseAsDefaultPool`.
If you want to build multiple connection pools, you should use InitMultiPools instead.
func InitMultiPools ¶
func InitMultiPools(configs []*MultiDialConfig) error
InitMultiPools
Init multiple redis connection pools. You can specify name for each redis connection pool. And if you want to use one pool directly, you should set `Default` to be true.
If `Default` that value equals true are found more than 1 time, only the last one is taken. And its name will be set as `defaultPoolName`.
func InitPool ¶
func InitPool(name string, config *DialConfig) (*redis.Pool, error)
InitPool Init redis connection pool with given name, so can fetch it again by this give name through `iRedis.Pool(name string)`
func NewPool ¶
func NewPool(config *DialConfig) (*redis.Pool, error)
NewPool
Just create a redis connection pool, you should persist it by yourself. RegisterPool can be used to persist it.
func Pool ¶
Pool
Fetch a redis connection pool with given name. If no name given, use `defaultPoolName` to fetch the default pool.
func RegisterPool ¶
RegisterPool
Persist a redis connection pool with given name. If this name exists, pool will be replaced by this new one, and the old pool will be closed.
func UseAsDefaultPool ¶
func UseAsDefaultPool(name string)
UseAsDefaultPool
Change the `defaultPoolName` value. Use this func with InitPool to call Pool directly without parameter name if parameter name of InitPool is not "default".
Types ¶
type DialConfig ¶
type DialConfig struct { Host string `toml:"host" json:"host,omitempty" yaml:"host" mapstructure:"host"` Port int `toml:"port" json:"port,omitempty" yaml:"port" mapstructure:"port"` Database int `toml:"database" json:"database,omitempty" yaml:"database" mapstructure:"database"` Password string `toml:"password" json:"password,omitempty" yaml:"password" mapstructure:"password"` MaxIdle int `toml:"max-idle" json:"max-idle,omitempty" yaml:"max-idle" mapstructure:"max-idle"` MaxActive int `toml:"max-active" json:"max-active,omitempty" yaml:"max-active" mapstructure:"max-active"` Wait bool `toml:"wait" json:"wait,omitempty" yaml:"wait" mapstructure:"wait"` ConnectTimeout time.Duration `toml:"connect-timeout" json:"connect-timeout,omitempty" yaml:"connect-timeout" mapstructure:"connect-timeout"` ReadTimeout time.Duration `toml:"read-timeout" json:"read-timeout,omitempty" yaml:"read-timeout" mapstructure:"read-timeout"` MaxConnLifetime time.Duration `toml:"max-conn-lifetime" json:"max-conn-lifetime,omitempty" yaml:"max-conn-lifetime" mapstructure:"max-conn-lifetime"` IdleTimeout time.Duration `toml:"idle-timeout" json:"idle-timeout,omitempty" yaml:"idle-timeout" mapstructure:"idle-timeout"` }
type MultiDialConfig ¶
type MultiDialConfig struct { Name string `toml:"name"` Default bool `toml:"default"` Config *DialConfig `toml:"config"` }
type Subscription ¶
type Subscription struct { Context context.Context RedisPool *redis.Pool RestartDuration time.Duration PingDuration time.Duration // contains filtered or unexported fields }
func NewSubscription ¶
func NewSubscription(opts Options) (*Subscription, error)
func (*Subscription) Start ¶
func (r *Subscription) Start()
func (*Subscription) Stop ¶
func (r *Subscription) Stop()
func (*Subscription) Subscribe ¶
func (r *Subscription) Subscribe(channel string, processor SubscriptionProcessor) error