gredis

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MASTER                        ACC_TYPE = "w"
	SLAVE                         ACC_TYPE = "r"
	DEFAULT_POOL_SIZE             int      = 10   //默认最大连接数
	DEFAULT_MIN_IDLE_CONN         int      = 5    //默认闲置连接数
	DEFAULT_SMART_MAX_CONN        int      = 5000 // 智能模式下,redis最大连接数上限
	DEFAULT_SMART_MIN_IDLE_CONN   int      = 1000 // 智能模式下, redis最小闲置连接数
	DEFAULT_PER_CPU_MAX_CONN      int      = 50   // 智能模式下, 每CPU支持的最大连接数
	DEFAULT_PER_CPU_MIN_IDLE_CONN int      = 5    // 智能模式下,每cpu支持的最小闲置连接数
)

Variables

View Source
var (
	ERR_CACHE_NAME_NOT_FOUND  = errors.New("redis name empty")
	ERR_CACHE_GROUP_NOT_FOUND = errors.New("redis node not found")
	ERR_CACHE_CONN_NOT_FOUND  = errors.New("redis connect invalid")
)

错误码

Functions

This section is empty.

Types

type ACC_TYPE

type ACC_TYPE string

type CACHEConf

type CACHEConf struct {
	GroupConfList []CACHEGroupConf `toml:"Group"`
}

多redis实例,配置

type CACHEConn

type CACHEConn struct {
	// contains filtered or unexported fields
}

单个cache连接

func (*CACHEConn) InjectClusterCtx

func (cacheConn *CACHEConn) InjectClusterCtx(client *redis.ClusterClient) func(old func(cmd redis.Cmder) error) func(cmd redis.Cmder) error

func (*CACHEConn) InjectClusterPipelineCtx

func (cacheConn *CACHEConn) InjectClusterPipelineCtx(client *redis.ClusterClient) func(oldProcess func([]redis.Cmder) error) func([]redis.Cmder) error

将ctx注入go redis的pipeline语句中

func (*CACHEConn) InjectCtx

func (cacheConn *CACHEConn) InjectCtx(client *redis.Client) func(old func(cmd redis.Cmder) error) func(cmd redis.Cmder) error

将ctx注入到go redis上下文环境

func (*CACHEConn) InjectPipelineCtx

func (cacheConn *CACHEConn) InjectPipelineCtx(client *redis.Client) func(oldProcess func([]redis.Cmder) error) func([]redis.Cmder) error

将ctx注入go redis的pipeline语句中

func (*CACHEConn) NewWrapperClient

func (cacheConn *CACHEConn) NewWrapperClient(ctx context.Context) (currentClient *redis.Client, err error)

func (*CACHEConn) NewWrapperClusterClient

func (cacheConn *CACHEConn) NewWrapperClusterClient(ctx context.Context) (currentClient *redis.ClusterClient, err error)

type CACHEConnConf

type CACHEConnConf struct {
	Host         string `toml:"host"` // host+端口
	Port         int    `toml:"port"` // 端口
	PoolSize     int    //每个CPU上的默认最大连接总数, 默认是10
	MinIdleConns int    //最小空闲连接数
}

单实例配置

type CACHEGroup

type CACHEGroup struct {
	Master []*CACHEConn

	Slave []*CACHEConn

	Cluster *CACHEConn
	// contains filtered or unexported fields
}

Redis主从组

func (*CACHEGroup) ChooseClusterConn

func (cacheGroup *CACHEGroup) ChooseClusterConn(ctx context.Context) (currentClient *redis.ClusterClient, err error)

func (*CACHEGroup) ChooseConn

func (cacheGroup *CACHEGroup) ChooseConn(ctx context.Context, accessType ACC_TYPE) (currentClient *redis.Client, err error)

选择连接

type CACHEGroupConf

type CACHEGroupConf struct {
	Name     string `toml:"name"`
	Password string `toml:"password"` // 密码

	Master  *CACHESubGroupConf `toml:"Master"`  // 主库配置
	Slaves  *CACHESubGroupConf `toml:"Slave"`   // 从库配置
	Cluster *CACHESubGroupConf `toml:"Cluster"` // cluster配置
}

Redis主从配置

type CACHEManager

type CACHEManager struct {
	GroupMap map[string]*CACHEGroup
}

CACHE总管理器

var GERedis *CACHEManager

单例管理器

func NewRedis

func NewRedis(config *CACHEConf) (cacheMgr *CACHEManager, err error)

func (*CACHEManager) Instance

func (cacheMgr *CACHEManager) Instance(ctx context.Context, name string, optionFuncs ...OptionFunc) (cacheClient *CacheClient, err error)

获取redis主从实例

func (*CACHEManager) InstanceCluster

func (cacheMgr *CACHEManager) InstanceCluster(ctx context.Context, name string) (client *redis.ClusterClient, err error)

获取redis集群实例

type CACHESubGroupConf

type CACHESubGroupConf struct {
	DialTimeout              time.Duration   `toml:"dialTimeout"`              // 连接超时时间
	ReadTimeout              time.Duration   `toml:"readTimeout"`              //  读-超时
	WriteTimeout             time.Duration   `toml:"writeTimeout"`             // 写-超时
	PoolSize                 int             `toml:"poolSize"`                 //每个CPU上的默认最大连接总数, 默认是10
	MinIdleConns             int             `toml:"minIdleConns"`             //最小空闲连接数
	ConnMode                 int             `toml:"connMode"`                 // 连接模式,0正常模式, 1自动根据cpu核数和pod数设置连接数
	DefaultSmartMaxConn      int             `toml:"defaultSmartMaxConn"`      // 智能模式下,redis最大连接数上限
	DefaultSmartMinIdleConn  int             `toml:"defaultSmartMinIdleConn"`  // 智能模式下, redis最小闲置连接数
	DefaultPerCpuMaxConn     int             `toml:"defaultPerCpuMaxConn"`     // 智能模式下, 每CPU支持的最大连接数
	DefaultPerCpuMinIdleConn int             `toml:"defaultPerCpuMinIdleConn"` // 智能模式下,每cpu支持的最小闲置连接数
	PoolTimeout              time.Duration   `toml:"poolTimeout"`              //所有的连接打满后,请求超时时间 Default is ReadTimeout + 1 second
	IdleTimeout              time.Duration   `toml:"idleTimeout"`              //闲置请求超时时间, Default is 5 minutes. -1 disables idle timeout check.
	Instances                []CACHEConnConf `toml:"Instance"`                 // 实例列表
}

Master 或者 Slave配置

type CacheClient

type CacheClient struct {
	// contains filtered or unexported fields
}

func (*CacheClient) Append

func (cacheClient *CacheClient) Append(key, value string) *redis.IntCmd

func (*CacheClient) BLPop

func (cacheClient *CacheClient) BLPop(timeout time.Duration, keys ...string) *redis.StringSliceCmd

func (*CacheClient) BRPop

func (cacheClient *CacheClient) BRPop(timeout time.Duration, keys ...string) *redis.StringSliceCmd

func (*CacheClient) BRPopLPush

func (cacheClient *CacheClient) BRPopLPush(source, destination string, timeout time.Duration) *redis.StringCmd

func (*CacheClient) BitCount

func (cacheClient *CacheClient) BitCount(key string, bitCount *redis.BitCount) *redis.IntCmd

func (*CacheClient) BitOpAnd

func (cacheClient *CacheClient) BitOpAnd(destKey string, keys ...string) *redis.IntCmd

func (*CacheClient) BitOpNot

func (cacheClient *CacheClient) BitOpNot(destKey string, key string) *redis.IntCmd

func (*CacheClient) BitOpOr

func (cacheClient *CacheClient) BitOpOr(destKey string, keys ...string) *redis.IntCmd

func (*CacheClient) BitOpXor

func (cacheClient *CacheClient) BitOpXor(destKey string, keys ...string) *redis.IntCmd

func (*CacheClient) BitPos

func (cacheClient *CacheClient) BitPos(key string, bit int64, pos ...int64) *redis.IntCmd

func (*CacheClient) Decr

func (cacheClient *CacheClient) Decr(key string) *redis.IntCmd

func (*CacheClient) DecrBy

func (cacheClient *CacheClient) DecrBy(key string, decrement int64) *redis.IntCmd

func (*CacheClient) Del

func (cacheClient *CacheClient) Del(keys ...string) *redis.IntCmd

func (*CacheClient) Exists

func (cacheClient *CacheClient) Exists(keys ...string) *redis.IntCmd

func (*CacheClient) Expire

func (cacheClient *CacheClient) Expire(key string, expiration time.Duration) *redis.BoolCmd

func (*CacheClient) ExpireAt

func (cacheClient *CacheClient) ExpireAt(key string, tm time.Time) *redis.BoolCmd

func (*CacheClient) Get

func (cacheClient *CacheClient) Get(key string) *redis.StringCmd

func (*CacheClient) GetBit

func (cacheClient *CacheClient) GetBit(key string, offset int64) *redis.IntCmd

func (*CacheClient) GetRange

func (cacheClient *CacheClient) GetRange(key string, start, end int64) *redis.StringCmd

func (*CacheClient) GetSet

func (cacheClient *CacheClient) GetSet(key string, value interface{}) *redis.StringCmd

func (*CacheClient) HDel

func (cacheClient *CacheClient) HDel(key string, fields ...string) *redis.IntCmd

func (*CacheClient) HExists

func (cacheClient *CacheClient) HExists(key, field string) *redis.BoolCmd

func (*CacheClient) HGet

func (cacheClient *CacheClient) HGet(key, field string) *redis.StringCmd

func (*CacheClient) HGetAll

func (cacheClient *CacheClient) HGetAll(key string) *redis.StringStringMapCmd

func (*CacheClient) HIncrBy

func (cacheClient *CacheClient) HIncrBy(key, field string, incr int64) *redis.IntCmd

func (*CacheClient) HIncrByFloat

func (cacheClient *CacheClient) HIncrByFloat(key, field string, incr float64) *redis.FloatCmd

func (*CacheClient) HKeys

func (cacheClient *CacheClient) HKeys(key string) *redis.StringSliceCmd

func (*CacheClient) HLen

func (cacheClient *CacheClient) HLen(key string) *redis.IntCmd

func (*CacheClient) HMGet

func (cacheClient *CacheClient) HMGet(key string, fields ...string) *redis.SliceCmd

func (*CacheClient) HMSet

func (cacheClient *CacheClient) HMSet(key string, fields map[string]interface{}) *redis.StatusCmd

func (*CacheClient) HScan

func (cacheClient *CacheClient) HScan(key string, cursor uint64, match string, count int64) *redis.ScanCmd

func (*CacheClient) HSet

func (cacheClient *CacheClient) HSet(key, field string, value interface{}) *redis.BoolCmd

func (*CacheClient) HSetNX

func (cacheClient *CacheClient) HSetNX(key, field string, value interface{}) *redis.BoolCmd

func (*CacheClient) HVals

func (cacheClient *CacheClient) HVals(key string) *redis.StringSliceCmd

func (*CacheClient) Incr

func (cacheClient *CacheClient) Incr(key string) *redis.IntCmd

func (*CacheClient) IncrBy

func (cacheClient *CacheClient) IncrBy(key string, value int64) *redis.IntCmd

func (*CacheClient) IncrByFloat

func (cacheClient *CacheClient) IncrByFloat(key string, value float64) *redis.FloatCmd

func (*CacheClient) LIndex

func (cacheClient *CacheClient) LIndex(key string, index int64) *redis.StringCmd

func (*CacheClient) LInsert

func (cacheClient *CacheClient) LInsert(key, op string, pivot, value interface{}) *redis.IntCmd

func (*CacheClient) LInsertAfter

func (cacheClient *CacheClient) LInsertAfter(key string, pivot, value interface{}) *redis.IntCmd

func (*CacheClient) LInsertBefore

func (cacheClient *CacheClient) LInsertBefore(key string, pivot, value interface{}) *redis.IntCmd

func (*CacheClient) LLen

func (cacheClient *CacheClient) LLen(key string) *redis.IntCmd

func (*CacheClient) LPop

func (cacheClient *CacheClient) LPop(key string) *redis.StringCmd

func (*CacheClient) LPush

func (cacheClient *CacheClient) LPush(key string, values ...interface{}) *redis.IntCmd

func (*CacheClient) LPushX

func (cacheClient *CacheClient) LPushX(key string, value interface{}) *redis.IntCmd

func (*CacheClient) LRange

func (cacheClient *CacheClient) LRange(key string, start, stop int64) *redis.StringSliceCmd

func (*CacheClient) LRem

func (cacheClient *CacheClient) LRem(key string, count int64, value interface{}) *redis.IntCmd

func (*CacheClient) LSet

func (cacheClient *CacheClient) LSet(key string, index int64, value interface{}) *redis.StatusCmd

func (*CacheClient) LTrim

func (cacheClient *CacheClient) LTrim(key string, start, stop int64) *redis.StatusCmd

func (*CacheClient) MGet

func (cacheClient *CacheClient) MGet(keys ...string) *redis.SliceCmd

func (*CacheClient) MSet

func (cacheClient *CacheClient) MSet(pairs ...interface{}) *redis.StatusCmd

func (*CacheClient) MSetNX

func (cacheClient *CacheClient) MSetNX(pairs ...interface{}) *redis.BoolCmd

func (*CacheClient) PExpire

func (cacheClient *CacheClient) PExpire(key string, expiration time.Duration) *redis.BoolCmd

func (*CacheClient) PExpireAt

func (cacheClient *CacheClient) PExpireAt(key string, tm time.Time) *redis.BoolCmd

func (*CacheClient) PTTL

func (cacheClient *CacheClient) PTTL(key string) *redis.DurationCmd

func (*CacheClient) PipelineMaster

func (cacheClient *CacheClient) PipelineMaster() redis.Pipeliner

func (*CacheClient) PipelineSlave

func (cacheClient *CacheClient) PipelineSlave() redis.Pipeliner

func (*CacheClient) PipelinedMaster

func (cacheClient *CacheClient) PipelinedMaster(fn func(pipeliner redis.Pipeliner) error) ([]redis.Cmder, error)

func (*CacheClient) PipelinedSlave

func (cacheClient *CacheClient) PipelinedSlave(fn func(pipeliner redis.Pipeliner) error) ([]redis.Cmder, error)

func (*CacheClient) RPop

func (cacheClient *CacheClient) RPop(key string) *redis.StringCmd

func (*CacheClient) RPopLPush

func (cacheClient *CacheClient) RPopLPush(source, destination string) *redis.StringCmd

func (*CacheClient) RPush

func (cacheClient *CacheClient) RPush(key string, values ...interface{}) *redis.IntCmd

func (*CacheClient) RPushX

func (cacheClient *CacheClient) RPushX(key string, value interface{}) *redis.IntCmd

func (*CacheClient) Rename

func (cacheClient *CacheClient) Rename(key, newkey string) *redis.StatusCmd

func (*CacheClient) RenameNX

func (cacheClient *CacheClient) RenameNX(key, newkey string) *redis.BoolCmd

func (*CacheClient) SAdd

func (cacheClient *CacheClient) SAdd(key string, members ...interface{}) *redis.IntCmd

func (*CacheClient) SCard

func (cacheClient *CacheClient) SCard(key string) *redis.IntCmd

func (*CacheClient) SDiff

func (cacheClient *CacheClient) SDiff(keys ...string) *redis.StringSliceCmd

func (*CacheClient) SDiffStore

func (cacheClient *CacheClient) SDiffStore(destination string, keys ...string) *redis.IntCmd

func (*CacheClient) SInter

func (cacheClient *CacheClient) SInter(keys ...string) *redis.StringSliceCmd

func (*CacheClient) SInterStore

func (cacheClient *CacheClient) SInterStore(destination string, keys ...string) *redis.IntCmd

func (*CacheClient) SIsMember

func (cacheClient *CacheClient) SIsMember(key string, member interface{}) *redis.BoolCmd

func (*CacheClient) SMembers

func (cacheClient *CacheClient) SMembers(key string) *redis.StringSliceCmd

func (*CacheClient) SMembersMap

func (cacheClient *CacheClient) SMembersMap(key string) *redis.StringStructMapCmd

func (*CacheClient) SMove

func (cacheClient *CacheClient) SMove(source, destination string, member interface{}) *redis.BoolCmd

func (*CacheClient) SPop

func (cacheClient *CacheClient) SPop(key string) *redis.StringCmd

func (*CacheClient) SPopN

func (cacheClient *CacheClient) SPopN(key string, count int64) *redis.StringSliceCmd

func (*CacheClient) SRandMember

func (cacheClient *CacheClient) SRandMember(key string) *redis.StringCmd

func (*CacheClient) SRandMemberN

func (cacheClient *CacheClient) SRandMemberN(key string, count int64) *redis.StringSliceCmd

func (*CacheClient) SRem

func (cacheClient *CacheClient) SRem(key string, members ...interface{}) *redis.IntCmd

func (*CacheClient) SScan

func (cacheClient *CacheClient) SScan(key string, cursor uint64, match string, count int64) *redis.ScanCmd

func (*CacheClient) SUnion

func (cacheClient *CacheClient) SUnion(keys ...string) *redis.StringSliceCmd

func (*CacheClient) SUnionStore

func (cacheClient *CacheClient) SUnionStore(destination string, keys ...string) *redis.IntCmd

func (*CacheClient) Scan

func (cacheClient *CacheClient) Scan(cursor uint64, match string, count int64) *redis.ScanCmd

func (*CacheClient) Set

func (cacheClient *CacheClient) Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd

func (*CacheClient) SetBit

func (cacheClient *CacheClient) SetBit(key string, offset int64, value int) *redis.IntCmd

func (*CacheClient) SetNX

func (cacheClient *CacheClient) SetNX(key string, value interface{}, expiration time.Duration) *redis.BoolCmd

func (*CacheClient) SetRange

func (cacheClient *CacheClient) SetRange(key string, offset int64, value string) *redis.IntCmd

func (*CacheClient) SetXX

func (cacheClient *CacheClient) SetXX(key string, value interface{}, expiration time.Duration) *redis.BoolCmd

func (*CacheClient) StrLen

func (cacheClient *CacheClient) StrLen(key string) *redis.IntCmd

func (*CacheClient) TTL

func (cacheClient *CacheClient) TTL(key string) *redis.DurationCmd

func (*CacheClient) TxPipelineMaster

func (cacheClient *CacheClient) TxPipelineMaster() redis.Pipeliner

func (*CacheClient) TxPipelineSlave

func (cacheClient *CacheClient) TxPipelineSlave() redis.Pipeliner

func (*CacheClient) TxPipelinedMaster

func (cacheClient *CacheClient) TxPipelinedMaster(fn func(pipeliner redis.Pipeliner) error) ([]redis.Cmder, error)

func (*CacheClient) TxPipelinedSlave

func (cacheClient *CacheClient) TxPipelinedSlave(fn func(pipeliner redis.Pipeliner) error) ([]redis.Cmder, error)

func (*CacheClient) WithForceMaster

func (cacheClient *CacheClient) WithForceMaster() (clonedCacheClient *CacheClient)

func (*CacheClient) ZAdd

func (cacheClient *CacheClient) ZAdd(key string, members ...redis.Z) *redis.IntCmd

func (*CacheClient) ZAddCh

func (cacheClient *CacheClient) ZAddCh(key string, members ...redis.Z) *redis.IntCmd

func (*CacheClient) ZAddNX

func (cacheClient *CacheClient) ZAddNX(key string, members ...redis.Z) *redis.IntCmd

func (*CacheClient) ZAddNXCh

func (cacheClient *CacheClient) ZAddNXCh(key string, members ...redis.Z) *redis.IntCmd

func (*CacheClient) ZAddXX

func (cacheClient *CacheClient) ZAddXX(key string, members ...redis.Z) *redis.IntCmd

func (*CacheClient) ZAddXXCh

func (cacheClient *CacheClient) ZAddXXCh(key string, members ...redis.Z) *redis.IntCmd

func (*CacheClient) ZCard

func (cacheClient *CacheClient) ZCard(key string) *redis.IntCmd

func (*CacheClient) ZCount

func (cacheClient *CacheClient) ZCount(key, min, max string) *redis.IntCmd

func (*CacheClient) ZIncr

func (cacheClient *CacheClient) ZIncr(key string, member redis.Z) *redis.FloatCmd

func (*CacheClient) ZIncrBy

func (cacheClient *CacheClient) ZIncrBy(key string, increment float64, member string) *redis.FloatCmd

func (*CacheClient) ZIncrNX

func (cacheClient *CacheClient) ZIncrNX(key string, member redis.Z) *redis.FloatCmd

func (*CacheClient) ZIncrXX

func (cacheClient *CacheClient) ZIncrXX(key string, member redis.Z) *redis.FloatCmd

func (*CacheClient) ZInterStore

func (cacheClient *CacheClient) ZInterStore(destination string, store redis.ZStore, keys ...string) *redis.IntCmd

func (*CacheClient) ZLexCount

func (cacheClient *CacheClient) ZLexCount(key, min, max string) *redis.IntCmd

func (*CacheClient) ZPopMax

func (cacheClient *CacheClient) ZPopMax(key string, count ...int64) *redis.ZSliceCmd

func (*CacheClient) ZPopMin

func (cacheClient *CacheClient) ZPopMin(key string, count ...int64) *redis.ZSliceCmd

func (*CacheClient) ZRange

func (cacheClient *CacheClient) ZRange(key string, start, stop int64) *redis.StringSliceCmd

func (*CacheClient) ZRangeByLex

func (cacheClient *CacheClient) ZRangeByLex(key string, opt redis.ZRangeBy) *redis.StringSliceCmd

func (*CacheClient) ZRangeByScore

func (cacheClient *CacheClient) ZRangeByScore(key string, opt redis.ZRangeBy) *redis.StringSliceCmd

func (*CacheClient) ZRangeByScoreWithScores

func (cacheClient *CacheClient) ZRangeByScoreWithScores(key string, opt redis.ZRangeBy) *redis.ZSliceCmd

func (*CacheClient) ZRangeWithScores

func (cacheClient *CacheClient) ZRangeWithScores(key string, start, stop int64) *redis.ZSliceCmd

func (*CacheClient) ZRank

func (cacheClient *CacheClient) ZRank(key, member string) *redis.IntCmd

func (*CacheClient) ZRem

func (cacheClient *CacheClient) ZRem(key string, members ...interface{}) *redis.IntCmd

func (*CacheClient) ZRemRangeByLex

func (cacheClient *CacheClient) ZRemRangeByLex(key, min, max string) *redis.IntCmd

func (*CacheClient) ZRemRangeByRank

func (cacheClient *CacheClient) ZRemRangeByRank(key string, start, stop int64) *redis.IntCmd

func (*CacheClient) ZRemRangeByScore

func (cacheClient *CacheClient) ZRemRangeByScore(key, min, max string) *redis.IntCmd

func (*CacheClient) ZRevRange

func (cacheClient *CacheClient) ZRevRange(key string, start, stop int64) *redis.StringSliceCmd

func (*CacheClient) ZRevRangeByLex

func (cacheClient *CacheClient) ZRevRangeByLex(key string, opt redis.ZRangeBy) *redis.StringSliceCmd

func (*CacheClient) ZRevRangeByScore

func (cacheClient *CacheClient) ZRevRangeByScore(key string, opt redis.ZRangeBy) *redis.StringSliceCmd

func (*CacheClient) ZRevRangeByScoreWithScores

func (cacheClient *CacheClient) ZRevRangeByScoreWithScores(key string, opt redis.ZRangeBy) *redis.ZSliceCmd

func (*CacheClient) ZRevRangeWithScores

func (cacheClient *CacheClient) ZRevRangeWithScores(key string, start, stop int64) *redis.ZSliceCmd

func (*CacheClient) ZRevRank

func (cacheClient *CacheClient) ZRevRank(key, member string) *redis.IntCmd

func (*CacheClient) ZScan

func (cacheClient *CacheClient) ZScan(key string, cursor uint64, match string, count int64) *redis.ScanCmd

func (*CacheClient) ZScore

func (cacheClient *CacheClient) ZScore(key, member string) *redis.FloatCmd

type CacheOptions

type CacheOptions struct {
	// contains filtered or unexported fields
}

访问实例时的配置项

type OptionFunc

type OptionFunc func(options *CacheOptions)

配置注入func

func WithForceMaster

func WithForceMaster() OptionFunc

强制读主

Jump to

Keyboard shortcuts

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