redishelper

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: MIT Imports: 4 Imported by: 0

README

redishelper

github.com/go-redis/redis/v8的帮助程序

特性

  • 提供一个未设置被代理对象的默认代理对象Proxy
  • 可以代理Client,ClusterClient,FailoverClusterClient
  • 设置被代理对象时可以串行或者并行的执行注册的回调函数,回调函数只能在未设置被代理客户端时注册
  • 代理对象一旦被设置则无法替换
  • 封装了一些常用的工具
    • github.com/Golang-Tools/redishelper/bitmap封装了分布式位图,可以用于相对低空间占用的去重并且满足全部集合操作满足CanBeSetCanBeClientKey接口
    • github.com/Golang-Tools/redishelper/broker封装了redis支持的3种可以用作中间人的数据结构(queue,stream,pubsub),统一按生产者(CanBeProducerCanBeClientKey接口)消费者(CanBeConsumerCanBeClientKeyBatch接口)模式进行了封装
    • github.com/Golang-Tools/redishelper/cache封装了分布式缓存,支持使用分布式锁和分布式限制器控制缓存的执行策略,同时支持自动更新同步缓存内容,满足CanBeClientKey接口
    • github.com/Golang-Tools/redishelper/counter对象封装了分布式累加器,它也可以用于作为分布式系统的id生成器,满足接口CanBeCounterCanBeClientKey
    • github.com/Golang-Tools/redishelper/hypercount用于为大规模数据做去重计数和一部分集合操作,满足CanBeDisctinctCounterCanBeClientKey接口
    • github.com/Golang-Tools/redishelper/limiter限制器,用于限流和缓存防击穿等,满足接口CanBeLimiter
    • github.com/Golang-Tools/redishelper/lock分布式锁,用于避免分布式系统中的资源争抢,满足接口CanlockCanBeClientKey
    • github.com/Golang-Tools/redishelper/namespace用于构造命名空间的辅助工具
    • github.com/Golang-Tools/redishelper/proxy用于给github.com/go-redis/redis/v8中的客户端对象提供代理,满足接口redis.UniversalClient
    • github.com/Golang-Tools/redishelper/randomkey用于生成随机的key
    • github.com/Golang-Tools/redishelper/ranker排序工具封装,满足接口CanBeClientKey
    • github.com/Golang-Tools/redishelper/scanfinder封装了使用scan遍历全局keys的方法

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CanBeClientKey

type CanBeClientKey interface {
	Exists(context.Context) (bool, error)
	Type(context.Context) (string, error)
	CanHanddlerLifeCycle
}

type CanBeClientKeyBatch

type CanBeClientKeyBatch interface {
	AllExists(context.Context) (bool, error)
	AnyExists(ctx context.Context) (bool, error)
	Types(ctx context.Context) (map[string]string, error)
	HasSameType(ctx context.Context) (bool, string, error)
	ToArray()
	CanHanddlerLifeCycle
}

type CanBeConsumer

type CanBeConsumer interface {
	RegistHandler(topic string, fn event.Handdler) error
	UnRegistHandler(topic string) error
	Listen(asyncHanddler bool, p ...event.Parser) error
	StopListening() error
}

CanBeConsumer 消费者对象的接口

type CanBeCount

type CanBeCount interface {
	Len(context.Context) (int64, error)
	Reset(context.Context) error
}

CanBeCount 可以被计数

type CanBeCounter

type CanBeCounter interface {
	CanBeGenerator
	CanBeCount
}

CanBeCounter 计数器接口

type CanBeDisctinctCounter

type CanBeDisctinctCounter interface {
	CanBeCount
	Add(context.Context, ...interface{}) error
	AddM(context.Context, ...interface{}) error
	Union(context.Context, *clientkey.ClientKey, ...CanBeDisctinctCounter) (CanBeDisctinctCounter, error)
}

type CanBeGenerator

type CanBeGenerator interface {
	Next(context.Context) (int64, error)
}

CanBeGenerator 生成器的接口

type CanBeLimiter

type CanBeLimiter interface {
	//注水,返回值true表示注水成功,false表示满了无法注水,抛出异常返回true
	Flood(context.Context, int64) (bool, error)
	//水位
	WaterLevel(context.Context) (int64, error)
	//容量
	Capacity() int64
	//是否容量已满
	IsFull(context.Context) (bool, error)
	//重置
	Reset(context.Context) error
}

CanBeLimiter 限制器接口

type CanBeProducer

type CanBeProducer interface {
	Publish(ctx context.Context, payload interface{}) error
	PubEvent(ctx context.Context, payload interface{}) (*event.Event, error)
}

CanBeProducer 生产者对象的接口

type CanBeSet

type CanBeSet interface {
	CanBeDisctinctCounter
	Remove(context.Context, ...interface{}) error
	RemoveM(context.Context, ...interface{}) error
	Contained(context.Context, interface{}) (bool, error)
	ToArray(context.Context) ([]interface{}, error)
	Intersection(context.Context, *clientkey.ClientKey, ...CanBeSet) (CanBeSet, error)
	Except(context.Context, *clientkey.ClientKey, CanBeSet) (CanBeSet, error)
	Xor(context.Context, *clientkey.ClientKey, CanBeSet) (CanBeSet, error)
}

CanBeSet 可以被看作时Set的结构对象

type CanHanddlerLifeCycle

type CanHanddlerLifeCycle interface {
	TTL(context.Context) (time.Duration, error)
	Delete(context.Context) error
	RefreshTTL(context.Context) error
	AutoRefresh() error
	StopAutoRefresh(bool) error
}

type Canlock

type Canlock interface {
	Lock(context.Context) error
	Unlock(context.Context) error
	Wait(context.Context) error
}

Canlock 锁对象的接口

Directories

Path Synopsis
Package bitmap bitmap操作支持 bitmap可以用于分布式去重 bitmap实现了一般set的常用接口(Add,Remove,Contained,Len,ToArray)
Package bitmap bitmap操作支持 bitmap可以用于分布式去重 bitmap实现了一般set的常用接口(Add,Remove,Contained,Len,ToArray)
pubsub
Package 发布订阅器对象 Package pubsub 发布订阅器对象 非常适合作为简单的广播模式的中间件
Package 发布订阅器对象 Package pubsub 发布订阅器对象 非常适合作为简单的广播模式的中间件
queue
Package queue 队列对象 非常适合作为简单的生产者消费者模式的中间件 Package queue 队列对象 非常适合作为简单的生产者消费者模式的中间件 Package queue 队列对象 非常适合作为简单的生产者消费者模式的中间件
Package queue 队列对象 非常适合作为简单的生产者消费者模式的中间件 Package queue 队列对象 非常适合作为简单的生产者消费者模式的中间件 Package queue 队列对象 非常适合作为简单的生产者消费者模式的中间件
stream
Package stream 流及相关对象的包 Package stream 流及相关对象的包
Package stream 流及相关对象的包 Package stream 流及相关对象的包
Package cache 缓存对象 更新缓存往往是竞争更新,因此需要使用分布式锁避免重复计算,同时等待更新完成后再取数据.
Package cache 缓存对象 更新缓存往往是竞争更新,因此需要使用分布式锁避免重复计算,同时等待更新完成后再取数据.
Package key redis的key包装 Package key redis的key包装
Package key redis的key包装 Package key redis的key包装
clientkeybatch
Package clientkeybatch redis的keybatch包装
Package clientkeybatch redis的keybatch包装
counter
hashcounter
Package counter Counter操作支持 Counter可以用于分布式累加计数
Package counter Counter操作支持 Counter可以用于分布式累加计数
keycounter
Package keycounter string型计数器
Package keycounter string型计数器
ext
redis_cell/limiter
Package limiter 限制器 可以用于防止短时间内大量请求同时处理,比如缓存防击穿,防爬虫等
Package limiter 限制器 可以用于防止短时间内大量请求同时处理,比如缓存防击穿,防爬虫等
Package hypercount 面向对象的计数估计类型 HyperCount 用于粗略统计大量数据去重后的个数,一般用在日活计算
Package hypercount 面向对象的计数估计类型 HyperCount 用于粗略统计大量数据去重后的个数,一般用在日活计算
Package keyspace_notifications对象
Package keyspace_notifications对象
Package limiter 限制器 可以用于防止短时间内大量请求同时处理,比如缓存防击穿,防爬虫等
Package limiter 限制器 可以用于防止短时间内大量请求同时处理,比如缓存防击穿,防爬虫等
Package lock 分布式锁实现 分布式锁需要有客户端信息,只可以获得锁的客户端自己解锁或者等待锁自己过期 当未能获得锁需要等待锁释放时可以通过wait接口实现
Package lock 分布式锁实现 分布式锁需要有客户端信息,只可以获得锁的客户端自己解锁或者等待锁自己过期 当未能获得锁需要等待锁释放时可以通过wait接口实现
Package randomkey 随机生成一个key 使用sony实现的snowflake算法 默认的设置为 StartTime: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),MachineID则会默认尝试使用本机的第一张网卡的mac地址最后1位,如果获取不到则会使用默认值0
Package randomkey 随机生成一个key 使用sony实现的snowflake算法 默认的设置为 StartTime: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),MachineID则会默认尝试使用本机的第一张网卡的mac地址最后1位,如果获取不到则会使用默认值0
Package ranker 排序器类型 ranker可以用于分布式排序操作 即多个worker分别计算更新一部分元素的权重,业务端则只负责读取结果
Package ranker 排序器类型 ranker可以用于分布式排序操作 即多个worker分别计算更新一部分元素的权重,业务端则只负责读取结果
Package scanfinder 使用scan遍历查询的工具
Package scanfinder 使用scan遍历查询的工具

Jump to

Keyboard shortcuts

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