redis

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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 HashInfo

type HashInfo struct {
	Field string `json:"field"`
	Value string `json:"value"`
}

type KeyTTLInfo

type KeyTTLInfo struct {
	Key string        `json:"key"`
	TTL time.Duration `json:"ttl"`
}

type Option

type Option func(*Options)

func DB

func DB(db int) Option

func DialTimeoutMs

func DialTimeoutMs(dialTimeoutMs int) Option

func Host

func Host(host string) Option

func IdleTimeoutMs

func IdleTimeoutMs(idleTimeoutMs int) Option

func Network

func Network(network string) Option

func Password

func Password(password string) Option

func Port

func Port(port int) Option

func ReadTimeoutMs

func ReadTimeoutMs(readTimeoutMs int) Option

func Username

func Username(username string) Option

func WriteTimeoutMs

func WriteTimeoutMs(writeTimeoutMs int) Option

type Options

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

type Redis

type Redis struct {
	Client *redis.Client
}

func (*Redis) CheckKeysTTL

func (r *Redis) CheckKeysTTL(ctx context.Context, keys []string) (ktInfo []KeyTTLInfo, err error)

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) Init

func (r *Redis) Init(options ...Option) (err error)

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() 方法使用.

Jump to

Keyboard shortcuts

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