Documentation
¶
Index ¶
- Constants
- type HashInfo
- type KeyTTLInfo
- type Option
- func DB(db int) Option
- func DialTimeoutMs(dialTimeoutMs int) Option
- func Host(host string) Option
- func IdleTimeoutMs(idleTimeoutMs int) Option
- func Network(network string) Option
- func Password(password string) Option
- func Port(port int) Option
- func ReadTimeoutMs(readTimeoutMs int) Option
- func Username(username string) Option
- func WriteTimeoutMs(writeTimeoutMs int) Option
- type Options
- type Redis
- func (r *Redis) CheckKeysTTL(ctx context.Context, keys []string) (ktInfo []KeyTTLInfo, err error)
- func (r *Redis) DelHashInfosByBatch(ctx context.Context, hashKey string, chHash <-chan HashInfo, delBatchSize uint) (err error)
- func (r *Redis) DelKeysByBatch(ctx context.Context, chKey <-chan string, delBatchSize uint) (err error)
- func (r *Redis) Init(options ...Option) (err error)
- func (r *Redis) ScanHashInfos(ctx context.Context, hashKey string, cursor uint64, match string, count int64, ...)
- func (r *Redis) ScanKeys(ctx context.Context, cursor uint64, match string, count int64, ...)
Constants ¶
const ( DefaultNetwork = "tcp" DefaultHost = "127.0.0.1" DefaultPort = 6379 DefaultUsername = "" DefaultPassword = "" DefaultDB = 0 DefaultDialTimeoutMs = 1000 * 5 DefaultReadTimeoutMs = 1000 * 3 DefaultWriteTimeoutMs = 1000 * 3 DefaultIdleTimeoutMs = 1000 * 60 * 5 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyTTLInfo ¶
type Option ¶
type Option func(*Options)
func DialTimeoutMs ¶
func IdleTimeoutMs ¶
func ReadTimeoutMs ¶
func WriteTimeoutMs ¶
type Redis ¶
type Redis struct {
Client *redis.Client
}
func (*Redis) CheckKeysTTL ¶
CheckKeysTTL 批量检查 key 的过期时间. 可结合 ScanKeys() 方法使用, 具体可参考 redis_test.go TestCheckKeysTTL() 方法使用.
func (*Redis) DelHashInfosByBatch ¶
func (r *Redis) DelHashInfosByBatch(ctx context.Context, hashKey string, chHash <-chan HashInfo, delBatchSize uint) (err error)
DelHashInfosByBatch 通过传递 chHash <-chan HashInfo , 批量删除 hashKey 里的 field 从而达到删除 hashKey 的功能. delBatchSize 默认 100, 代表每批次删除 field 的数量大小. 可结合 ScanHashInfos() 方法使用, 具体可参考 redis_test.go TestDelHashInfosByBatch() 方法使用.
func (*Redis) DelKeysByBatch ¶
func (r *Redis) DelKeysByBatch(ctx context.Context, chKey <-chan string, delBatchSize uint) (err error)
DelKeysByBatch 通过传递 chKey <-chan string , 批量删除 key. delBatchSize 默认 100, 代表每批次删除 key 的数量大小. 可结合 ScanKeys() 方法使用, 具体可参考 redis_test.go TestDelKeysByBatch() 方法使用.
func (*Redis) ScanHashInfos ¶
func (r *Redis) ScanHashInfos(ctx context.Context, hashKey string, cursor uint64, match string, count int64, chHash chan<- HashInfo)
ScanHashInfos 通过 hscan 命令查找 hashKey 中与 match 匹配的 fields. 此方法已经开启了一个 goroutine 执行. 当 match="" 时相当于全 hashKey 扫描, match 可以是正则表达式, eg: test* / test_* / test:* / *test* 等等. 可参考 redis_test.go TestScanHashInfos() 方法使用.
func (*Redis) ScanKeys ¶
func (r *Redis) ScanKeys(ctx context.Context, cursor uint64, match string, count int64, chKey chan<- string)
ScanKeys 通过 scan 命令查找与 match 匹配的 keys. 此方法已经开启了一个 goroutine 执行. 当 match="" 时相当于全库扫描, match 可以是正则表达式, eg: test* / test_* / test:* / *test* 等等. 可参考 redis_test.go TestScanKeys() 方法使用.