pRedis

package
v0.0.0-...-2a66b16 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

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

func Pool(name ...string) (*redis.Pool, error)

Pool

Fetch a redis connection pool with given name. If no name given, use `defaultPoolName` to fetch the default pool.

func RegisterPool

func RegisterPool(name string, pool *redis.Pool)

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 Lock

type Lock struct {
	Pool        *redis.Pool
	LockSeconds int
}

func NewLock

func NewLock(pool *redis.Pool) *Lock

func (*Lock) Acquire

func (r *Lock) Acquire(lock string, lockSeconds int) error

func (*Lock) Release

func (r *Lock) Release(lock string) error

type MultiDialConfig

type MultiDialConfig struct {
	Name    string      `toml:"name"`
	Default bool        `toml:"default"`
	Config  *DialConfig `toml:"config"`
}

type Options

type Options struct {
	Ctx             context.Context
	Pool            *redis.Pool
	RestartDuration time.Duration
	PingDuration    time.Duration
}

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

type SubscriptionProcessor

type SubscriptionProcessor func(ctx context.Context, msg redis.Message) error

Jump to

Keyboard shortcuts

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