redisproxy

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOpts = Options{
	StandAloneOptions: &redis.Options{Addr: "localhost:6379"},
	Type:              Redis_Standalone,
	Parallelcallback:  false,
	Hooks:             []redis.Hook{},
}
View Source
var ErrProxyAllreadySettedUniversalClient = errors.New("proxy allready setted universal client")

ErrProxyAllreadySettedUniversalClient 代理已经设置过redis客户端对象

View Source
var ErrProxyNotYetSettedUniversalClient = errors.New("proxy notSet universal client yet")

ErrProxyNotYetSettedUniversalClient 代理还未设置客户端对象

View Source
var ErrUnknownClientType = errors.New("unknown client type")

ErrUnknownClientType 未知的redis客户端类型

Functions

func WithClusterOptions

func WithClusterOptions(RedisOptions *redis.ClusterOptions) optparams.Option[Options]

WithClusterOptions 使用特定redis集群连接设置

func WithFailoverClusterOptions

func WithFailoverClusterOptions(RedisOptions *redis.FailoverOptions) optparams.Option[Options]

WithFailoverOptions 使用特定redis集群哨兵连接设置

func WithFailoverOptions

func WithFailoverOptions(RedisOptions *redis.FailoverOptions) optparams.Option[Options]

WithFailoverOptions 使用特定redis哨兵连接设置

func WithHooks

func WithHooks(hooks ...redis.Hook) optparams.Option[Options]

WithHooks 增加redis钩子

func WithOptions

func WithOptions(RedisOptions *redis.Options) optparams.Option[Options]

WithOptions 使用特定单机redis连接设置

func WithParallelCallback

func WithParallelCallback() optparams.Option[Options]

WithParallelCallback 设置初始化后回调并行执行而非串行执行

func WithQueryTimeoutMS

func WithQueryTimeoutMS(QueryTimeout int) optparams.Option[Options]

WithQueryTimeoutMS 设置最大请求超时,单位ms

func WithRingOptions

func WithRingOptions(RedisOptions *redis.RingOptions) optparams.Option[Options]

WithRingOptions 使用特定redis的Ring集群连接设置

func WithURL

func WithURL(URL string) optparams.Option[Options]

WithURL 使用特定url设置单机redis的连接

Types

type Callback

type Callback func(cli redis.UniversalClient) error

Callback redis操作的回调函数

type Options

type Options struct {
	Type              RedisType
	Parallelcallback  bool
	QueryTimeout      time.Duration
	StandAloneOptions *redis.Options
	ClusterOptions    *redis.ClusterOptions
	FailoverOptions   *redis.FailoverOptions
	RingOptions       *redis.RingOptions
	Hooks             []redis.Hook
}

Option 设置key行为的选项

type RedisProxy added in v2.0.2

type RedisProxy struct {
	redis.UniversalClient
	// contains filtered or unexported fields
}

RedisProxy redis客户端的代理

var Default *RedisProxy

Default 默认的redis代理对象

func New

func New() *RedisProxy

New 创建一个新的数据库客户端代理

func (*RedisProxy) Init added in v2.0.2

func (proxy *RedisProxy) Init(opts ...optparams.Option[Options]) error

func (*RedisProxy) IsOk added in v2.0.2

func (proxy *RedisProxy) IsOk() bool

IsOk 检查代理是否已经可用

func (*RedisProxy) NewCtx added in v2.0.2

func (proxy *RedisProxy) NewCtx() (ctx context.Context, cancel context.CancelFunc)

NewCtx 根据注册的超时时间构造一个上下文

func (*RedisProxy) Regist added in v2.0.2

func (proxy *RedisProxy) Regist(cb Callback) error

Regist 注册回调函数,在init执行后执行回调函数 如果对象已经设置了被代理客户端则无法再注册回调函数

func (*RedisProxy) SetConnect added in v2.0.2

func (proxy *RedisProxy) SetConnect(cli redis.UniversalClient) error

SetConnect 设置连接的客户端 @params cli UniversalClient 满足redis.UniversalClient接口的对象的指针

type RedisType

type RedisType int32

redis类型

const (
	Redis_Standalone      RedisType = 0
	Redis_Cluster         RedisType = 1
	Redis_Failover        RedisType = 2
	Redis_FailoverCluster RedisType = 3
	Redis_Ring            RedisType = 4
)

Jump to

Keyboard shortcuts

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