redisx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 5 Imported by: 4

README

redisx

封装了 go-redis,支持单机和集群

配置

type Config struct {
    // 是否为集群模式
    Cluster  bool   `mapstructure:"cluster" `
    // 主机
    Host     string `mapstructure:"host" `
    // 端口
    Port     string `mapstructure:"port" `
    // 密码
    Password string `mapstructure:"password"`
    // 连接协议
    Protocol string `mapstructure:"protocol"`
    // 初始连接的数据库
    Database int    `mapstructure:"database"`
    // 最小空闲连接
    MinIdleConns int `mapstructure:"min_idle_conns"`
    // 空闲时间
    IdleTimeout int `mapstructure:"idle_timeout"`
    // 连接池大小
    PoolSize int `mapstructure:"pool_size"`
    // 连接最大可用时间
    MaxConnAge int `mapstructure:"max_conn_age"`
}
安装

go get -u -v github.com/itmisx/redisx

使用

参考 redix_test.go,详细请查看 github: https://github.com/go-redis/redis

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Subscribe(ctx context.Context, channels ...string) *redis.PubSub
	redis.Cmdable
	Close() error
}

Redis接口定义 因要兼容单例和集群,所以需定义接口,来兼容 接口定义了什么方法,外部才可以调用什么方法

func New

func New(conf Config) Client

New 新建redis实例

type Config

type Config struct {
	Cluster  bool   `mapstructure:"cluster" `
	Host     string `mapstructure:"host" `
	Port     string `mapstructure:"port" `
	Password string `mapstructure:"password"`
	Protocol string `mapstructure:"protocol"`
	Database int    `mapstructure:"database"`
	// 最小空闲连接
	MinIdleConns int `mapstructure:"min_idle_conns"`
	// 空闲时间
	IdleTimeout int `mapstructure:"idle_timeout"`
	// 连接池大小
	PoolSize int `mapstructure:"pool_size"`
	// 连接最大可用时间
	MaxConnAge int `mapstructure:"max_conn_age"`
}

Redis 配置项

Jump to

Keyboard shortcuts

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