redis

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttrExpr = "expr" //过期时间
	AttrNx   = "nx"   // setNx
)
View Source
const (
	SerializerJson       = "json"
	SerializerSimpleJson = "simplejson"
	SerializerString     = "string"
)

Variables

View Source
var (
	Rdb  *redis.Client
	RdbC *redis.ClusterClient
)

Functions

func InitClusterRedis

func InitClusterRedis(adds []string, password string) (err error)

InitClusterRedis 初始化连接 集群

func InitRedis

func InitRedis(host string, port int, password string, db int) (err error)

InitRedis 初始化连接 普通连接

func InitSentinelRedis

func InitSentinelRedis(adds []string, masterName string, password string, db int) (err error)

InitSentinelRedis 初始化连接 哨兵模式

Types

type DBGttFunc

type DBGttFunc func() string

type Iterator

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

func NewIterator

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

func (*Iterator) HasNext

func (i *Iterator) HasNext() bool

func (*Iterator) Next

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

type JsonGttFunc

type JsonGttFunc func() interface{}

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
	SimpleJsonGetter SimpleJsonGttFunc // 缓存不存在的操作 SimpleJson
	Serializer       string            // 序列化方式
}

SimpleCache 缓存

func NewSimpleCache

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

func (*SimpleCache) GetCache

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

GetCache 获取缓存

func (*SimpleCache) GetCacheSimpleJson

func (c *SimpleCache) GetCacheSimpleJson(key string) (js *simplejson.Json)

GetCacheSimpleJson 获取缓存配合SimpleJson插件

func (*SimpleCache) SetCache

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

SetCache 设置缓存

type SimpleJsonGttFunc

type SimpleJsonGttFunc func() *simplejson.Json

type SliceResult

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

func NewSliceResult

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

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 NewStringOperation

func NewStringOperation() *StringOperation

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

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

Jump to

Keyboard shortcuts

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