cache

package
v0.0.0-...-50176c9 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRedisMaxIdle     = 2
	DefaultRedisIdleTimeout = 120 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cacher

type Cacher interface {
	Get(key string, target interface{}) bool
	GetString(key string) string
	GetBool(key string) bool
	GetFloat64(key string) float64
	GetInt(key string) int
	Exists(key string) bool
	Delete(key string)
	// Set 放置值
	Set(key string, value interface{})
	SetExpired(key string, value interface{}, t time.Duration)
	Close()
}

Cacher 缓存接口

type Redis

type Redis struct {
	Pool *redis.Pool
}

func Default

func Default(host string, port int, password ...string) *Redis

func New

func New(pool *redis.Pool) *Redis

func (*Redis) Close

func (r *Redis) Close()

Close 关闭redis 链接

func (*Redis) Delete

func (r *Redis) Delete(key string)

Delete 删除key

func (*Redis) Exists

func (r *Redis) Exists(key string) bool

Exists 判断key是否存在

func (*Redis) Get

func (r *Redis) Get(key string, target interface{}) bool

Get 根据key获取值 如果存在key,则返回值,true,如果不存在,返回nil,false

func (*Redis) GetBool

func (r *Redis) GetBool(key string) bool

func (*Redis) GetConn

func (r *Redis) GetConn() redis.Conn

GetConn 获取链接

func (*Redis) GetFloat64

func (r *Redis) GetFloat64(key string) float64

func (*Redis) GetInt

func (r *Redis) GetInt(key string) int

func (*Redis) GetString

func (r *Redis) GetString(key string) string

func (*Redis) Set

func (r *Redis) Set(key string, value interface{})

Set 放置值

func (*Redis) SetExpired

func (r *Redis) SetExpired(key string, value interface{}, expire time.Duration)

SetExpired 放置值 如果value 为非 golang 基本类型,则转换成, 如果 expire 为<=0,那么不设置过期时间

Jump to

Keyboard shortcuts

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