eRedis

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoInit = errors.New("eRedis: please initialize with eRedis.Init()")

Functions

func GetClient

func GetClient(name string, defaultDB int) *redis.Client

GetClient 获取redis客户端 @param name 配置名 @param defaultDB 默认数据库 @return *redis.Client

func GetClientByConf

func GetClientByConf(conf Conf, db int) (*redis.Client, error)

GetClientByConf 获取redis客户端 @param conf 配置 @param defaultDB 默认数据库 @return *redis.Client

func Init

func Init(connectConf map[string]Conf)

Init 初始化 Example:

connectConf = map[string]Conf{
		"localhost": {
			Host:        viper.GetString("REDIS_LOCALHOST_RW_HOST"),
			Password:    viper.GetString("REDIS_LOCALHOST_RW_PASSWORD"),
			Port:        viper.GetInt("REDIS_LOCALHOST_RW_PORT"),
			PoolSize:    viper.GetInt("REDIS_LOCALHOST_POOL_SIZE"),
			MinIdleConn: viper.GetInt("REDIS_LOCALHOST_MIN_IDLE_CONN"),
			IdleTimeout: viper.GetDuration("REDIS_LOCALHOST_IDLE_TIMEOUT"),
		},
	}

Types

type Conf

type Conf struct {
	Host        string
	Password    string
	Port        int
	PoolSize    int
	MinIdleConn int
	IdleTimeout time.Duration
}

type ERedis

type ERedis struct {
	ConfName string
	DB       int
}

ERedis 在结构体引入组合并赋值RedisConfName、RedisDB,即可通过RDB()获取redis连接 Example

type User struct {
	 eRedis.DB
}

var user = User{ConfName: "localhost", DB: 1}

func (u *User) GetUser() {
	 u.RDB().Get(key)
}

func (*ERedis) Del added in v0.0.7

func (r *ERedis) Del(c context.Context, keys ...string) error

func (*ERedis) RDB

func (r *ERedis) RDB() *redis.Client

RDB 获取redis连接 @return *redis.Client

Jump to

Keyboard shortcuts

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