redisx

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BloomKey      = "bloom"
	BloomCapacity = 10000
	BloomError    = 0.01
)
View Source
const (
	UnLockScript string = `
	if redis.call('GET', KEYS[1]) == ARGV[1] then
		return redis.call('DEL', KEYS[1])
	else 
		return 0 
	end
`
	KeepLockScript string = `
	if redis.call('GET', KEYS[1]) == ARGV[1] then
		return redis.call('PEXPIRE', KEYS[1], ARGV[2]) 
	else
		return 0 
	end
`
)
View Source
const (
	// ClusterType means redis cluster.
	ClusterType = "cluster"
	// NodeType means redis node.
	NodeType = "node"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlackWhiteUser

type BlackWhiteUser struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

func NewBlackWhite

func NewBlackWhite() *BlackWhiteUser

func (*BlackWhiteUser) AddToBlackList

func (this *BlackWhiteUser) AddToBlackList(user string) error

AddToBlackList 加入黑名单

func (*BlackWhiteUser) AddToWhiteList

func (this *BlackWhiteUser) AddToWhiteList(user string) error

AddToWhiteList 加入白名单

func (*BlackWhiteUser) CheckBlackList

func (this *BlackWhiteUser) CheckBlackList(user string) (bool, error)

CheckBlackList 用于检查请求IP是否在黑名单中,如果是则返回true,否则返回false

func (*BlackWhiteUser) CheckWhiteList

func (this *BlackWhiteUser) CheckWhiteList(user string) (bool, error)

CheckWhiteList 用于检查请求IP是否在白名单中,如果是则返回true,否则返回false

func (*BlackWhiteUser) FindList

func (this *BlackWhiteUser) FindList(types blackType) []string

FindList 名单查看,传常量进来

func (*BlackWhiteUser) RemoveBlackList

func (this *BlackWhiteUser) RemoveBlackList(user string) error

RemoveBlackList 更新黑名单状态和有效期

func (*BlackWhiteUser) RemoveWhiteList

func (this *BlackWhiteUser) RemoveWhiteList(user string) error

RemoveWhiteList 更新白名单状态和有效期

func (*BlackWhiteUser) SetExpire

func (this *BlackWhiteUser) SetExpire(key string, duration time.Duration) bool

SetExpire 设置过期时间

type BloomFilter

type BloomFilter interface {
	Reserve(key string, errorRate float64, capacity uint64) error
	Add(key string, item string) (bool, error)
	Exists(key string, item string) (bool, error)
}

type CacheSession

type CacheSession interface {
	TakeCtx(ctx context.Context, value interface{}, key string, queryDB func(val interface{}) error) error
	TakeExpireCtx(ctx context.Context, value interface{}, key string, queryDB func(val interface{}) error) error

	SetCtx(ctx context.Context, key string, val interface{}) error
	SetExpireCtx(ctx context.Context, key string, val interface{}, expire time.Duration) error

	GetCtx(ctx context.Context, key string, val interface{}) error
	DelCtx(ctx context.Context, keys ...string) error
}

func NewSqlCache

func NewSqlCache(conf *gofkConf.RedisConfig) CacheSession

type Checker

type Checker interface {
	AddToBlackList(string) error //加入黑名单
	AddToWhiteList(string) error //加入白名单

	RemoveWhiteList(string) error //从白名单中删除
	RemoveBlackList(string) error //从黑名单中删除

	CheckWhiteList(string) (bool, error) //判断是否在白名单
	CheckBlackList(string) (bool, error) //判断是否在黑名单

	FindList(string) []string //名单查看,传常量进来
}

type LockOptionFunc

type LockOptionFunc func(option *lockOption)

func WithLockTTL

func WithLockTTL(lt time.Duration) LockOptionFunc

func WithRedisClient

func WithRedisClient(cli *redis.Client) LockOptionFunc

func WithRedisConf

func WithRedisConf(conf *gofkConf.RedisConfig) LockOptionFunc

func WithWaitCAS

func WithWaitCAS(wt time.Duration) LockOptionFunc

type LockerInter

type LockerInter interface {
	SetKey(string) LockerInter
	Lock() error
	UnLock() (bool, error)
	WaitCAS() error
}

func NewLock

func NewLock(conf *gofkConf.RedisConfig, opts ...LockOptionFunc) LockerInter

func NewLockers

func NewLockers(clients []*redis.Client, conf *gofkConf.RedisConfig, opts ...LocksOptionFunc) LockerInter

type LocksOptionFunc

type LocksOptionFunc func(option *locksOptions)

type Redis

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

func NewNode

func NewNode(conf *gofkConf.RedisConfig) *Redis

func (*Redis) Client

func (s *Redis) Client() *redis.Client

func (*Redis) ClusterClient

func (s *Redis) ClusterClient() *redis.ClusterClient

func (*Redis) DelCtx

func (s *Redis) DelCtx(ctx context.Context, keys ...string) (val int, err error)

DelCtx deletes keys.

func (*Redis) GetCtx

func (s *Redis) GetCtx(ctx context.Context, key string) (val string, err error)

GetCtx s

func (*Redis) Node

func (s *Redis) Node() (RedisInter, error)

func (*Redis) SetCtx

func (s *Redis) SetCtx(ctx context.Context, key, value string, seconds int) error

SetCtx s

func (*Redis) TtlCtx

func (s *Redis) TtlCtx(ctx context.Context, key string) (val int, err error)

TtlCtx is the implementation of redis ttl command.

type RedisBloom

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

func NewRedisBloom

func NewRedisBloom(addr, name string, pass *string) *RedisBloom

func (*RedisBloom) Add

func (r *RedisBloom) Add(key string, item string) (bool, error)

func (*RedisBloom) Exists

func (r *RedisBloom) Exists(key string, item string) (bool, error)

func (*RedisBloom) Reserve

func (r *RedisBloom) Reserve(key string, errorRate float64, capacity uint64) error

type RedisInter

type RedisInter interface {
	redis.Cmdable
}

type RedisWrapper

type RedisWrapper interface {
	SetExpire(key string, duration time.Duration) bool

	GetAll(key string) map[string]string
	Sets(key string, value map[string]string) error
}

type Stat

type Stat struct {

	// export the fields to let the unit tests working,
	// reside in internal package, doesn't matter.
	Total   uint64
	Hit     uint64
	Miss    uint64
	DbFails uint64
	// contains filtered or unexported fields
}

A Stat is used to stat the cache.

func NewStat

func NewStat(name string) *Stat

NewStat returns a Stat.

func (*Stat) IncrementDbFails

func (s *Stat) IncrementDbFails()

IncrementDbFails 递增缓存数据库失败数。每次调用该方法,数据库失败数会增加1。

func (*Stat) IncrementHit

func (s *Stat) IncrementHit()

IncrementHit 用于递增命中数。每次调用该方法,命中数会增加1。

func (*Stat) IncrementMiss

func (s *Stat) IncrementMiss()

IncrementMiss 用于递增未命中数。每次调用该方法,未命中数会增加1。

func (*Stat) IncrementTotal

func (s *Stat) IncrementTotal()

IncrementTotal 用于递增总请求数。每次调用该方法,总请求数会增加1

Jump to

Keyboard shortcuts

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