storage_redis

package
v0.0.0-...-455e706 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRedisIsDown = errors.New("storage: Redis is either down or ws not configured")

当我们无法与redis通信时,会返回errRedisDown。

Functions

func ConnectToRedis

func ConnectToRedis(ctx context.Context, config *Config)

********************* ConnectToRedis启动一个go例程,定期尝试连接到redis(断开时候重连)。 并给redisUp 赋值说明此时redis能够正常连接 首先进行与redis连接初始化 pkg/redis 为其他服务使用做准备

func Connected

func Connected() bool

如果我们连接到redis,Connected返回true。

func DisableRedis

func DisableRedis(ok bool)

当redis正常连接时 说明不禁用(false)

func NewRedisClusterPool

func NewRedisClusterPool(isCache bool, config *Config) redis.UniversalClient

根据 config new Redis 新建RedisClusterPool创建redis集群池

Types

type Config

type Config struct {
	Host                  string   // 主机 (单机时候 host)
	Port                  int      // 端口
	Addrs                 []string // 集群的
	MasterName            string   // 主库名
	Username              string   // 用户名
	Password              string   // 密码
	Database              int      // redis那个库
	MaxIdle               int      // 最大空闲时间
	MaxActive             int      // 最大连接数
	Timeout               int      // 超时时间
	EnableCluster         bool     // 启用群集
	UseSSL                bool     // 使用加密
	SSLInsecureSkipVerify bool     // SSL不安全跳过验证 ??
}

配置定义redis群集的选项。

type RedisCluster

type RedisCluster struct {
	KeyPrefix string //  密钥前缀
	HashKeys  bool   // hash key
	IsCache   bool   //  是否缓存
}

RedisCluster是一个使用redis数据库的存储管理器,外部使用

func (*RedisCluster) Publish

func (r *RedisCluster) Publish(channel, message string) error

往 channel 中发送消息

func (*RedisCluster) StartPubSubHandler

func (r *RedisCluster) StartPubSubHandler(channel string, callback func(interface{})) error

StartSubsubHandler 监听信号并为其运行回调每个订阅和消息事件。

type RedisOpts

type RedisOpts redis.UniversalOptions // 通用选项

Jump to

Keyboard shortcuts

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