dredis

package module
v1.0.7 Latest Latest
Warning

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

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

README

Golang

📦 Golang Redis 缓存数据库

godoc goproxy.cn goreportcard.com deps.dev

安装

go get -u github.com/dtapps/go-redis

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
)

Functions

func InitRedis

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

InitRedis 初始化连接 普通连接

func Version

func Version() string

Types

type DBGttFunc

type DBGttFunc func() string

type DBGttInterfaceFunc added in v1.0.6

type DBGttInterfaceFunc func() interface{}

type DBGttJsonFunc added in v1.0.6

type DBGttJsonFunc func() interface{}

type DBGttSimpleJsonFunc added in v1.0.6

type DBGttSimpleJsonFunc func() *simplejson.Json

type DBGttStringFunc added in v1.0.6

type DBGttStringFunc 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 SimpleInterfaceCache added in v1.0.6

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

SimpleInterfaceCache 缓存

func NewSimpleInterfaceCache added in v1.0.6

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

func (*SimpleInterfaceCache) GetCache added in v1.0.6

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

GetCache 获取缓存

func (*SimpleInterfaceCache) SetCache added in v1.0.6

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

SetCache 设置缓存

type SimpleJsonCache added in v1.0.6

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

SimpleJsonCache 缓存

func NewSimpleJsonCache added in v1.0.6

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

func (*SimpleJsonCache) GetCache added in v1.0.6

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

GetCache 获取缓存

func (*SimpleJsonCache) SetCache added in v1.0.6

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

SetCache 设置缓存

type SimpleJsonGttFunc

type SimpleJsonGttFunc func() *simplejson.Json

type SimpleSimpleJsonCache added in v1.0.6

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

SimpleSimpleJsonCache 缓存

func NewSimpleSimpleJsonCache added in v1.0.6

func NewSimpleSimpleJsonCache(operation *StringOperation, expire time.Duration) *SimpleSimpleJsonCache

func (*SimpleSimpleJsonCache) GetCache added in v1.0.6

func (c *SimpleSimpleJsonCache) GetCache(key string) (js *simplejson.Json)

GetCache 获取缓存

func (*SimpleSimpleJsonCache) SetCache added in v1.0.6

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

SetCache 设置缓存

type SimpleStringCache added in v1.0.6

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

SimpleStringCache 缓存

func NewSimpleStringCache added in v1.0.6

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

func (*SimpleStringCache) GetCache added in v1.0.6

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

GetCache 获取缓存

func (*SimpleStringCache) SetCache added in v1.0.6

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

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