cache

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_TIMEOUT     = 86400 * 30 // 接近无限时间
	SESS_ONLINE_KEY = "onlines"  // 在线用户
	SESS_PREFIX     = "sess"     // 会话缓存前缀
	SESS_TIMEOUT    = 7200       // 会话缓存时间
	SESS_LIST_SEP   = ";"        // 角色名之间的分隔符
)

Variables

This section is empty.

Functions

func BindUserInfo

func BindUserInfo(sess *RedisBackend, info map[string]string) error

绑定用户信息

func BindUserRoles added in v0.5.8

func BindUserRoles(sess *RedisBackend, uid string, roles []string) (string, error)

绑定用户角色,返回旧的sid

func ConnectRedisPool

func ConnectRedisPool(params schema.ConnParams) *rdspool.RedisPool

连接Redis

func DelRedisHash

func DelRedisHash(key string) bool

func DelSession

func DelSession(token string) bool

func SessListJoin

func SessListJoin(data []string) string

func SessListSplit

func SessListSplit(data string) []string

func SetRedisBackend

func SetRedisBackend(rdsConn rdspool.Redis)

Types

type ICacheBackend

type ICacheBackend interface {
	Connect(params schema.ConnParams) error
	Close() error
	ClearAll() error
	GetName() string
	GetTimeout() int
	Set(key string, value interface{}) (int, error)
	Get(key string) (interface{}, error)
	GetInt(key string) (int, error)
	GetString(key string) (string, error)
	GetAll() (interface{}, error)
	AddFlash(messages ...string) (int, error)
	GetFlashes(n int) ([]string, error)
}

缓存接口

type RedisBackend

type RedisBackend struct {
	Name    string
	Timeout int
	*rdspool.RedisHash
}

Redis哈希表缓存

func GetRedisHash

func GetRedisHash(key string, timeout int) *RedisBackend

func GetSession

func GetSession(token string) *RedisBackend

func NewRedisBackend

func NewRedisBackend(name string, timeout int) *RedisBackend

连接Redis

func (*RedisBackend) AddFlash

func (b *RedisBackend) AddFlash(messages ...string) (int, error)

func (*RedisBackend) ClearAll

func (b *RedisBackend) ClearAll() error

func (*RedisBackend) Close

func (b *RedisBackend) Close() error

func (*RedisBackend) Connect

func (b *RedisBackend) Connect(params schema.ConnParams) error

func (*RedisBackend) GetFlashes

func (b *RedisBackend) GetFlashes(n int) ([]string, error)

数量n为最大取出多少条消息,-1表示所有消息

func (*RedisBackend) GetName

func (b *RedisBackend) GetName() string

func (*RedisBackend) SetRedisInst

func (b *RedisBackend) SetRedisInst(pool rdspool.Redis) error

Jump to

Keyboard shortcuts

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