Documentation ¶
Index ¶
- Constants
- type BlackWhiteUser
- func (this *BlackWhiteUser) AddToBlackList(user string) error
- func (this *BlackWhiteUser) AddToWhiteList(user string) error
- func (this *BlackWhiteUser) CheckBlackList(user string) (bool, error)
- func (this *BlackWhiteUser) CheckWhiteList(user string) (bool, error)
- func (this *BlackWhiteUser) FindList(types blackType) []string
- func (this *BlackWhiteUser) RemoveBlackList(user string) error
- func (this *BlackWhiteUser) RemoveWhiteList(user string) error
- func (this *BlackWhiteUser) SetExpire(key string, duration time.Duration) bool
- type BloomFilter
- type CacheSession
- type Checker
- type LockOptionFunc
- type LockerInter
- type LocksOptionFunc
- type Redis
- func (s *Redis) Client() *redis.Client
- func (s *Redis) ClusterClient() *redis.ClusterClient
- func (s *Redis) DelCtx(ctx context.Context, keys ...string) (val int, err error)
- func (s *Redis) GetCtx(ctx context.Context, key string) (val string, err error)
- func (s *Redis) Node() (RedisInter, error)
- func (s *Redis) SetCtx(ctx context.Context, key, value string, seconds int) error
- func (s *Redis) TtlCtx(ctx context.Context, key string) (val int, err error)
- type RedisBloom
- type RedisInter
- type RedisWrapper
- type Stat
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 ¶
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 更新白名单状态和有效期
type BloomFilter ¶
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) ClusterClient ¶
func (s *Redis) ClusterClient() *redis.ClusterClient
func (*Redis) Node ¶
func (s *Redis) Node() (RedisInter, error)
type RedisBloom ¶
type RedisBloom struct {
// contains filtered or unexported fields
}
func NewRedisBloom ¶
func NewRedisBloom(addr, name string, pass *string) *RedisBloom
type RedisInter ¶
type RedisInter interface { redis.Cmdable }
type RedisWrapper ¶
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 (*Stat) IncrementDbFails ¶
func (s *Stat) IncrementDbFails()
IncrementDbFails 递增缓存数据库失败数。每次调用该方法,数据库失败数会增加1。
func (*Stat) IncrementMiss ¶
func (s *Stat) IncrementMiss()
IncrementMiss 用于递增未命中数。每次调用该方法,未命中数会增加1。
func (*Stat) IncrementTotal ¶
func (s *Stat) IncrementTotal()
IncrementTotal 用于递增总请求数。每次调用该方法,总请求数会增加1
Click to show internal directories.
Click to hide internal directories.