goredis

package module
v0.0.0-...-05c9766 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 7 Imported by: 5

Documentation

Index

Constants

View Source
const (
	AttrExpr = "expr" // 过期时间
	AttrNx   = "nx"   // 设置Nx
)
View Source
const (
	SerializerJson   = "json"
	SerializerString = "string"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Db       *redis.Client
	Addr     string // 地址
	Password string // 密码
	DB       int    // 数据库
	PoolSize int    // 连接池大小
}

App 实例

func (*App) InitClient

func (app *App) InitClient()

InitClient 初始化连接

func (*App) NewListOperation

func (app *App) NewListOperation() *ListOperation

NewListOperation 列表(list)类型数据操作 https://www.tizi365.com/archives/299.html

func (*App) NewSimpleCache

func (app *App) NewSimpleCache(operation *StringOperation, expire time.Duration, serializer string) *SimpleCache

NewSimpleCache 构造函数

func (*App) NewSimpleInterfaceCache

func (app *App) NewSimpleInterfaceCache(operation *StringOperation, expire time.Duration) *SimpleInterfaceCache

NewSimpleInterfaceCache 构造函数

func (*App) NewSimpleJsonCache

func (app *App) NewSimpleJsonCache(operation *StringOperation, expire time.Duration) *SimpleJsonCache

NewSimpleJsonCache 构造函数

func (*App) NewSimpleStringCache

func (app *App) NewSimpleStringCache(operation *StringOperation, expire time.Duration) *SimpleStringCache

NewSimpleStringCache 构造函数

func (*App) NewStringOperation

func (app *App) NewStringOperation() *StringOperation

type DBGttFunc

type DBGttFunc func() string

type DBGttInterfaceFunc

type DBGttInterfaceFunc func() interface{}

type DBGttJsonFunc

type DBGttJsonFunc func() interface{}

type DBGttStringFunc

type DBGttStringFunc func() string

type HashOperation

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

func NewHashOperation

func NewHashOperation(db *redis.Client, ctx context.Context) *HashOperation

NewHashOperation hash类型数据操作 https://www.tizi365.com/archives/296.html

func (*HashOperation) Get

func (cl *HashOperation) Get(key, field string) *redis.StringCmd

Get 根据key和field字段设置,field字段的值

func (*HashOperation) Set

func (cl *HashOperation) Set(key string, value interface{}) *redis.IntCmd

Set 根据key和field字段设置,field字段的值

type Iterator

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

func NewIterator

func NewIterator(data []interface{}) *Iterator

NewIterator 构造函数

func (*Iterator) HasNext

func (i *Iterator) HasNext() bool

HasNext 是否有下一个

func (*Iterator) Next

func (i *Iterator) Next() (Ret interface{})

Next 循环下一个

type JsonGttFunc

type JsonGttFunc func() interface{}

type ListOperation

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

func (*ListOperation) Index

func (cl *ListOperation) Index(key string, index int64) *redis.StringCmd

Index 根据索引坐标,查询key中的数据

func (*ListOperation) Insert

func (cl *ListOperation) Insert(key, op string, pivot, value interface{}) *redis.IntCmd

Insert 在指定位置插入数据

func (*ListOperation) LPop

func (cl *ListOperation) LPop(key string) *redis.StringCmd

LPop 从列表左边删除第一个数据,并返回删除的数据

func (*ListOperation) LPush

func (cl *ListOperation) LPush(key string, value interface{}) *redis.IntCmd

LPush 从列表左边插入数据

func (*ListOperation) LPushX

func (cl *ListOperation) LPushX(key string, value interface{}) *redis.IntCmd

LPushX 跟LPush的区别是,仅当列表存在的时候才插入数据

func (*ListOperation) Len

func (cl *ListOperation) Len(key string) *redis.IntCmd

Len 返回列表的大小

func (*ListOperation) RPop

func (cl *ListOperation) RPop(key string) *redis.StringCmd

RPop 从列表的右边删除第一个数据,并返回删除的数据

func (*ListOperation) RPush

func (cl *ListOperation) RPush(key string, value interface{}) *redis.IntCmd

RPush 从列表右边插入数据

func (*ListOperation) RPushX

func (cl *ListOperation) RPushX(key string, value interface{}) *redis.IntCmd

RPushX 跟RPush的区别是,仅当列表存在的时候才插入数据

func (*ListOperation) Range

func (cl *ListOperation) Range(key string, start, stop int64) *redis.StringSliceCmd

Range 返回列表的一个范围内的数据,也可以返回全部数据

func (*ListOperation) RangeAli

func (cl *ListOperation) RangeAli(key string) *redis.StringSliceCmd

RangeAli 返回key全部数据

func (*ListOperation) Rem

func (cl *ListOperation) Rem(key string, count int64, value interface{}) *redis.IntCmd

Rem 删除key中的数据

type OperationAttr

type OperationAttr struct {
	Name  string
	Value interface{}
}

func WithExpire

func WithExpire(t time.Duration) *OperationAttr

WithExpire 过期时间

func WithNX

func WithNX() *OperationAttr

type OperationAttrs

type OperationAttrs []*OperationAttr

func (OperationAttrs) Find

func (a OperationAttrs) Find(name string) interface{}

type SimpleCache

type SimpleCache struct {
	Operation  *StringOperation // 操作类
	Expire     time.Duration    // 过去时间
	DBGetter   DBGttFunc        // 缓存不存在的操作 DB
	JsonGetter JsonGttFunc      // 缓存不存在的操作 JSON
	Serializer string           // 序列化方式
}

SimpleCache 缓存

func (*SimpleCache) GetCache

func (c *SimpleCache) GetCache(key string) (ret interface{})

GetCache 获取缓存

func (*SimpleCache) SetCache

func (c *SimpleCache) SetCache(key string, value interface{})

SetCache 设置缓存

type SimpleInterfaceCache

type SimpleInterfaceCache struct {
	Operation *StringOperation   // 操作类
	Expire    time.Duration      // 过期时间
	DBGetter  DBGttInterfaceFunc // 缓存不存在的操作 DB
}

SimpleInterfaceCache 缓存

func (*SimpleInterfaceCache) GetCache

func (c *SimpleInterfaceCache) GetCache(key string) (ret string)

GetCache 获取缓存

func (*SimpleInterfaceCache) SetCache

func (c *SimpleInterfaceCache) SetCache(key string, value interface{})

SetCache 设置缓存

type SimpleJsonCache

type SimpleJsonCache struct {
	Operation *StringOperation // 操作类
	Expire    time.Duration    // 过期时间
	DBGetter  DBGttJsonFunc    // 缓存不存在的操作 DB
}

SimpleJsonCache 缓存

func (*SimpleJsonCache) GetCache

func (c *SimpleJsonCache) GetCache(key string) (ret interface{})

GetCache 获取缓存

func (*SimpleJsonCache) SetCache

func (c *SimpleJsonCache) SetCache(key string, value interface{})

SetCache 设置缓存

type SimpleStringCache

type SimpleStringCache struct {
	Operation *StringOperation // 操作类
	Expire    time.Duration    // 过期时间
	DBGetter  DBGttStringFunc  // 缓存不存在的操作 DB
}

SimpleStringCache 缓存

func (*SimpleStringCache) GetCache

func (c *SimpleStringCache) GetCache(key string) (ret string)

GetCache 获取缓存

func (*SimpleStringCache) SetCache

func (c *SimpleStringCache) SetCache(key string, value string)

SetCache 设置缓存

type SliceResult

type SliceResult struct {
	Result []interface{}
	Err    error
}

func NewSliceResult

func NewSliceResult(result []interface{}, err error) *SliceResult

NewSliceResult 构造函数

func (*SliceResult) Iter

func (r *SliceResult) Iter() *Iterator

func (*SliceResult) Unwrap

func (r *SliceResult) Unwrap() []interface{}

Unwrap 空值情况下返回错误

func (*SliceResult) UnwrapOr

func (r *SliceResult) UnwrapOr(defaults []interface{}) []interface{}

UnwrapOr 空值情况下设置返回默认值

type StringOperation

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

func (*StringOperation) Del

func (o *StringOperation) Del(keys ...string) *redis.IntCmd

Del 删除key操作,支持批量删除

func (*StringOperation) Get

func (o *StringOperation) Get(key string) *StringResult

Get 获取单个

func (*StringOperation) MGet

func (o *StringOperation) MGet(keys ...string) *SliceResult

MGet 获取多个

func (*StringOperation) Set

func (o *StringOperation) Set(key string, value interface{}, attrs ...*OperationAttr) *StringResult

Set 设置

type StringResult

type StringResult struct {
	Result string // 结果
	Err    error  // 错误
}

func NewStringResult

func NewStringResult(result string, err error) *StringResult

NewStringResult 构造函数

func (*StringResult) Unwrap

func (r *StringResult) Unwrap() string

Unwrap 空值情况下返回错误

func (*StringResult) UnwrapOr

func (r *StringResult) UnwrapOr(defaults string) string

UnwrapOr 空值情况下设置返回默认值

func (*StringResult) UnwrapOrElse

func (r *StringResult) UnwrapOrElse(f func() string) string

UnwrapOrElse 空值情况下设置返回其他

Jump to

Keyboard shortcuts

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