redis

package
v0.0.0-...-36f27ca Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 4 Imported by: 0

README

Redis 封装

实现方式

  • 通过对底层redis client的封装,实现接口Client来提供redis常用的一些操作
  • 当前封装的底层redis client是go-redisv8版本

实现目的

  • 在底层redis client之上增加一层接口封装,该接口供上层调用,有利于代码的扩展性
  • 在底层redis client发生替换或变化时,无需对Client接口协议协议进行变更,只需改变接口方法内的具体实现,增强了代码的可维护性

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNilErr

func IsNilErr(err error) bool

Types

type BoolResult

type BoolResult interface {
	Val() bool
	Result() (bool, error)
	// contains filtered or unexported methods
}

BoolResult the bool result for redis commands

type BoolSliceResult

type BoolSliceResult interface {
	Val() []bool
	Result() ([]bool, error)
	// contains filtered or unexported methods
}

BoolSliceResult is the bool slice result for redis commands

type Client

type Client interface {
	Commands

	Subscribe(ctx context.Context, channels ...string) PubSub
	PSubscribe(ctx context.Context, channels ...string) PubSub
}

func NewClient

func NewClient(opts ...Option) (Client, error)

type Commands

type Commands interface {
	Pipeline() Pipeliner

	Close() error

	BRPop(ctx context.Context, timeout time.Duration, keys ...string) StringSliceResult
	BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) StringResult

	Del(ctx context.Context, keys ...string) IntResult
	Eval(ctx context.Context, script string, keys []string, args ...interface{}) Result
	Exists(ctx context.Context, keys ...string) IntResult
	Expire(ctx context.Context, key string, expiration time.Duration) BoolResult
	FlushDB(ctx context.Context) StatusResult
	Get(ctx context.Context, key string) StringResult
	HDel(ctx context.Context, key string, fields ...string) IntResult
	HGet(ctx context.Context, key, field string) StringResult
	HGetAll(ctx context.Context, key string) StringStringMapResult
	HIncrBy(ctx context.Context, key, field string, incr int64) IntResult
	HKeys(ctx context.Context, key string) StringSliceResult
	HMGet(ctx context.Context, key string, fields ...string) SliceResult
	HScan(ctx context.Context, key string, cursor uint64, match string, count int64) ScanResult
	Scan(ctx context.Context, cursor uint64, match string, count int64) ScanResult
	HSet(ctx context.Context, key string, values ...interface{}) IntResult
	Incr(ctx context.Context, key string) IntResult
	Keys(ctx context.Context, pattern string) StringSliceResult
	LLen(ctx context.Context, key string) IntResult
	LPush(ctx context.Context, key string, values ...interface{}) IntResult
	LRange(ctx context.Context, key string, start, stop int64) StringSliceResult
	LRem(ctx context.Context, key string, count int64, value interface{}) IntResult
	LTrim(ctx context.Context, key string, start, stop int64) StatusResult
	MGet(ctx context.Context, keys ...string) SliceResult
	MSet(ctx context.Context, values ...interface{}) StatusResult
	Ping(ctx context.Context) StatusResult
	Publish(ctx context.Context, channel string, message interface{}) IntResult
	Rename(ctx context.Context, key, newkey string) StatusResult
	RenameNX(ctx context.Context, key, newkey string) BoolResult
	RPop(ctx context.Context, key string) StringResult
	RPopLPush(ctx context.Context, source, destination string) StringResult
	RPush(ctx context.Context, key string, values ...interface{}) IntResult
	SAdd(ctx context.Context, key string, members ...interface{}) IntResult
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) StatusResult
	SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) BoolResult
	MSetNX(ctx context.Context, values ...interface{}) BoolResult
	SMembers(ctx context.Context, key string) StringSliceResult
	SRem(ctx context.Context, key string, members ...interface{}) IntResult
	TTL(ctx context.Context, key string) DurationResult
	TxPipeline(ctx context.Context) Pipeliner
	Discard(ctx context.Context, pipe Pipeliner) error
}

type Config

type Config struct {
	Address  string
	Password string
	Database int

	// sentinel 模式配置
	MasterName       string
	SentinelPassword string
	MaxOpenConns     int
}

type DurationResult

type DurationResult interface {
	Val() time.Duration
	Result() (time.Duration, error)
	// contains filtered or unexported methods
}

DurationResult is the duration result for redis commands

type FloatResult

type FloatResult interface {
	Val() float64
	Result() (float64, error)
	// contains filtered or unexported methods
}

FloatResult is the float result for redis commands

type IntResult

type IntResult interface {
	Val() int64
	Result() (int64, error)
	// contains filtered or unexported methods
}

IntResult is the int result for redis commands

type IntSliceResult

type IntSliceResult interface {
	Val() []int64
	Result() ([]int64, error)
	// contains filtered or unexported methods
}

IntSliceResult is the int slice result for redis commands

type Option

type Option func(c *Config)

func Address

func Address(address string) Option

func Database

func Database(db int) Option

func MasterName

func MasterName(masterName string) Option

func MaxOpenConns

func MaxOpenConns(maxOpenConns int) Option

func Password

func Password(pwd string) Option

func SentinelPassword

func SentinelPassword(sentinelPwd string) Option

type Pipeliner

type Pipeliner interface {
	redis.StatefulCmdable
	Do(ctx context.Context, args ...interface{}) *redis.Cmd
	Process(ctx context.Context, cmd redis.Cmder) error
	Close() error
	Discard() error
	Exec(ctx context.Context) ([]redis.Cmder, error)
}

Pipeliner is interface for redis pipeline technique

type PubSub

type PubSub interface {
	Channel(opts ...redis.ChannelOption) <-chan *redis.Message
	ChannelSize(size int) <-chan *redis.Message
	ChannelWithSubscriptions(ctx context.Context, size int) <-chan interface{}
	Close() error
	Ping(ctx context.Context, payload ...string) error
	PSubscribe(ctx context.Context, patterns ...string) error
	PUnsubscribe(ctx context.Context, patterns ...string) error
	Receive(ctx context.Context) (interface{}, error)
	ReceiveMessage(ctx context.Context) (*redis.Message, error)
	ReceiveTimeout(ctx context.Context, timeout time.Duration) (interface{}, error)
	String() string
	Subscribe(ctx context.Context, channels ...string) error
	Unsubscribe(ctx context.Context, channels ...string) error
}

type Result

type Result interface {
	Val() interface{}
	Result() (interface{}, error)
	// contains filtered or unexported methods
}

Result is the common result for redis commands

type ScanResult

type ScanResult interface {
	Val() (keys []string, cursor uint64)
	Result() (keys []string, cursor uint64, err error)
	// contains filtered or unexported methods
}

ScanResult is the duration result for redis commands

type SliceResult

type SliceResult interface {
	Val() []interface{}
	Result() ([]interface{}, error)
	// contains filtered or unexported methods
}

SliceResult is the slice result for redis commands

type StatusResult

type StatusResult interface {
	Val() string
	Result() (string, error)
	// contains filtered or unexported methods
}

StatusResult is the status result for redis commands

type StringIntMapResult

type StringIntMapResult interface {
	Val() map[string]int64
	Result() (map[string]int64, error)
	// contains filtered or unexported methods
}

StringIntMapResult is the string int map result for redis commands

type StringResult

type StringResult interface {
	Val() string
	Result() (string, error)
	Scan(val interface{}) error
	// contains filtered or unexported methods
}

StringResult is the string result for redis commands

type StringSliceResult

type StringSliceResult interface {
	Val() []string
	Result() ([]string, error)
	// contains filtered or unexported methods
}

StringSliceResult is the string slice result for redis commands

type StringStringMapResult

type StringStringMapResult interface {
	Val() map[string]string
	Result() (map[string]string, error)
	// contains filtered or unexported methods
}

StringStringMapResult is the string string map result for redis commands

type StringStructMapResult

type StringStructMapResult interface {
	Val() map[string]struct{}
	Result() (map[string]struct{}, error)
	// contains filtered or unexported methods
}

StringStructMapResult is the string struct map result for redis commands

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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