redis

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleClusterUsage

func ExampleClusterUsage()

ExampleClusterUsage 使用示例

@see https://github.com/go-redis/redis

func ExampleUsage

func ExampleUsage()

ExampleUsage 使用示例

@see https://github.com/go-redis/redis

func GetClusterInstance

func GetClusterInstance() *redisLib.ClusterClient

GetClusterInstance 获取redis集群连接实例

func GetInstance

func GetInstance() *redisLib.Client

GetInstance 获取redis连接实例

获取由InitRedis方法实例化后的连接

func InitRedis

func InitRedis(conf Conf)

InitRedis 初始化redis连接

func InitRedisCluster

func InitRedisCluster(conf ClusterConf)

InitRedisCluster 初始化redis集群连接

func New

func New(conf Conf) *redisLib.Client

New 实例化新的实例

func NewCluster

func NewCluster(conf ClusterConf) *redisLib.ClusterClient

NewCluster 实例化新的实例

Types

type Addr

type Addr struct {
	Host     string `yaml:"host" toml:"host" json:"host" default:"localhost"` //主机地址
	Port     int    `yaml:"port" toml:"port" json:"port" default:"6379"`      //端口
	Username string `yaml:"username" toml:"username" json:"username"`         //用户名
	Password string `yaml:"password" toml:"password" json:"password"`         //密码
}

type ClusterConf

type ClusterConf struct {
	SSLEnable bool   `yaml:"ssl_enable" toml:"ssl_enable" json:"ssl_enable"` //是否启用ssl
	AddrList  []Addr `yaml:"addr_list" toml:"addr_list" json:"addr_list"`    //连接地址列表
}

ClusterConf 集群配置信息

<yaml example>

redis_cluster:

ssl_enable: false
addr_list:
  - host: 127.0.0.1
    port: 6379
    username: ""
    password: Mt583611
  - host: 127.0.0.1
    port: 6380
    username: ""
    password: Mt583611
  - host: 127.0.0.1
    port: 6381
    username: ""
    password: Mt583611

<toml example>

::redis cluster配置::

[redis_cluster]

ssl_enable = false

[[redis_cluster.addr_list]]

host = "localhost"

username = ""

port = 6379

password = ""

[[redis_cluster.addr_list]]

host = "localhost"

username = ""

port = 6380

password = ""

[[redis_cluster.addr_list]]

host = "localhost"

username = ""

port = 6381

password = ""

type Conf

type Conf struct {
	Addr
	Database  int  `yaml:"database" toml:"database" json:"database"`       //数据库名
	SSLEnable bool `yaml:"ssl_enable" toml:"ssl_enable" json:"ssl_enable"` //是否启用ssl
}

Conf 配置信息

<yaml example>

redis:

addr:
  host: "127.0.0.1"
  port: 6379
  username: ""
  password: ""
database: 0
ssl_enable: false

<toml example>

::redis配置::

redis

host = "localhost"

username = ""

port = 6379

password = ""

database = 0

ssl_enable = false

type OptionsClusterFields

type OptionsClusterFields struct {
	Addrs    []string //连接地址
	Password string   //密码
}

OptionsClusterFields 配置项字段

Jump to

Keyboard shortcuts

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