Documentation ¶
Index ¶
- Constants
- Variables
- func ExecMapBytes(exec ExecMulti, keys ...string) (map[string][]byte, error)
- func ExecMapFloat(exec ExecMulti, keys ...string) (map[string]float64, error)
- func ExecMapInt(exec ExecMulti, keys ...string) (map[string]int, error)
- func ExecMapInt64(exec ExecMulti, keys ...string) (map[string]int64, error)
- func ExecMapString(exec ExecMulti, keys ...string) (map[string]string, error)
- func GetJsonContent(data string) string
- func Map2Args(data Map, asJson bool) []any
- func NewRedisConn(cfg dialect.ConnConfig) (redis.Conn, error)
- func NewRedisConnDb(cfg dialect.ConnConfig, db int) (redis.Conn, error)
- func ReplyBool(reply any, err error) (bool, error)
- func SessListJoin(data []string) string
- func SessListSplit(data string) []string
- type CacheData
- type ExecMulti
- type Map
- type RedisContainer
- type RedisHash
- func (rh *RedisHash) Delete(keys ...string) (int, error)
- func (rh *RedisHash) DeleteAll() (bool, error)
- func (rh *RedisHash) Exec(cmd string, args ...any) (any, error)
- func (rh *RedisHash) Exists(key string) (bool, error)
- func (rh *RedisHash) Expire(timeout int) (bool, error)
- func (rh *RedisHash) GetAll() (any, error)
- func (rh *RedisHash) GetAllString() (map[string]string, error)
- func (rh *RedisHash) GetFloat(key string) (float64, error)
- func (rh *RedisHash) GetInt(key string) (int, error)
- func (rh *RedisHash) GetInt64(key string) (int64, error)
- func (rh *RedisHash) GetKeys() []string
- func (rh *RedisHash) GetMulti(keys ...string) (any, error)
- func (rh *RedisHash) GetSize() int
- func (rh *RedisHash) GetString(key string) (string, error)
- func (rh *RedisHash) GetTimeout(predict bool) int
- func (rh *RedisHash) GetVal(key string) (any, error)
- func (rh *RedisHash) IncrInt(key string, offset int) (int, error)
- func (rh *RedisHash) IncrInt64(key string, offset int64) (int64, error)
- func (rh *RedisHash) LoadForeignJson(data Map) (err error)
- func (rh *RedisHash) LoadForeignString(keys ...string) (result map[string]string, err error)
- func (rh *RedisHash) LoadMap(keys ...string) (data Map, err error)
- func (rh *RedisHash) LoadMapInt(keys ...string) (map[string]int, error)
- func (rh *RedisHash) LoadMapString(keys ...string) (map[string]string, error)
- func (rh *RedisHash) LoadSummary(data Map) (map[string]string, error)
- func (rh *RedisHash) OrigDelete(keys ...any) (int, error)
- func (rh *RedisHash) OrigMulti(cmd string, keys ...any) (any, error)
- func (rh *RedisHash) SaveForeignData(data Map) (ok bool, err error)
- func (rh *RedisHash) SaveMap(data Map, asJson bool) (bool, error)
- func (rh *RedisHash) SetNX(key string, value any) (int, error)
- func (rh *RedisHash) SetVal(key string, value any) (int, error)
- type RedisWrapper
- func (r *RedisWrapper) Delete(keys ...string) (int, error)
- func (r *RedisWrapper) DeleteAll() (bool, error)
- func (r *RedisWrapper) Exec(cmd string, args ...any) (any, error)
- func (r *RedisWrapper) Exists(key string) (bool, error)
- func (r *RedisWrapper) Expire(key string, timeout int) (bool, error)
- func (r *RedisWrapper) Find(wildcard string) ([]string, error)
- func (r *RedisWrapper) GetBytes(key string) ([]byte, error)
- func (r *RedisWrapper) GetFloat(key string) (float64, error)
- func (r *RedisWrapper) GetInt(key string) (int, error)
- func (r *RedisWrapper) GetInt64(key string) (int64, error)
- func (r *RedisWrapper) GetMaxReadDuration() time.Duration
- func (r *RedisWrapper) GetMulti(keys ...string) (any, error)
- func (r *RedisWrapper) GetSize() int
- func (r *RedisWrapper) GetStrLen(key string) (int, error)
- func (r *RedisWrapper) GetString(key string) (string, error)
- func (r *RedisWrapper) GetTimeout(key string) int
- func (r *RedisWrapper) IncrFloat(key string, offset float64) (float64, error)
- func (r *RedisWrapper) IncrInt(key string, offset int) (int, error)
- func (r *RedisWrapper) IncrInt64(key string, offset int64) (int64, error)
- func (r *RedisWrapper) LoadJson(key string, obj any) error
- func (r *RedisWrapper) LoadMap(keys ...string) (data Map, err error)
- func (r *RedisWrapper) LoadMapInt(keys ...string) (map[string]int, error)
- func (r *RedisWrapper) LoadMapString(keys ...string) (map[string]string, error)
- func (r *RedisWrapper) OrigDelete(keys ...any) (int, error)
- func (r *RedisWrapper) OrigMulti(cmd string, keys ...any) (any, error)
- func (r *RedisWrapper) Rename(old, dst string) (bool, error)
- func (r *RedisWrapper) SaveJson(key string, obj any, timeout int) (bool, error)
- func (r *RedisWrapper) SaveMap(data Map, asJson bool) (bool, error)
- func (r *RedisWrapper) SetNX(key string, value any) (int, error)
- func (r *RedisWrapper) SetPart(key string, value any, offset int) (int, error)
- func (r *RedisWrapper) SetVal(key string, value any, timeout int) (bool, error)
- type Session
- func (sess *Session) AddFlash(messages ...string) (int, error)
- func (sess *Session) BindRoles(uid string, roles []string, kick bool) (string, error)
- func (sess *Session) GetFlashes(n int) ([]string, error)
- func (sess *Session) GetKey() string
- func (sess *Session) WrapExec(cmd string, args ...any) (any, error)
- type SessionRegistry
Constants ¶
View Source
const ( REDIS_DEFAULT_IDLE_CONN = 3 // 最大空闲连接数 REDIS_DEFAULT_IDLE_TIMEOUT = 240 // 最大空闲时长,单位:秒 REDIS_DEFAULT_EXEC_RETRY = 3 // 重试次数 REDIS_DEFAULT_READ_TIMEOUT = 7 // 命令最大执行时长,单位:秒 )
View Source
const ( SESS_FOR_EVER = -1 // 无限 SESS_NOT_EXISTS = -2 // 不存在 SESS_ERR_REDIS = -3 // redis错误 SESS_PREFIX = "sess" // 会话缓存前缀 SESS_LIST_SEP = ";" // 角色名之间的分隔符 SESS_TOKEN_KEY = "_token_" SESS_ONLINE_KEY = "onlines" // 在线用户 MAX_TIMEOUT = 86400 * 30 // 接近无限时间 )
Variables ¶
View Source
var ( StrToList = utils.StrToList // 将字符串数组转为一般数组 KeysEmptyError = fmt.Errorf("the param which named 'keys' must not empty !") )
Functions ¶
func GetJsonContent ¶
对list、dict或string的json,去掉两边括号或引号取中间部分 用于快速拼接json,免除判断类型和空值,如 fmt.Sprintf("{%s}", GetJsonContent(json))
func NewRedisConn ¶
func NewRedisConn(cfg dialect.ConnConfig) (redis.Conn, error)
NewRedisConn 根据配置连接redis
cfg = dialect.ConnConfig{ DSN: (dialect.Redis{ Host: "127.0.0.1", Database: 3, }).BuildDSN(), Password: "secrect", }
func NewRedisConnDb ¶
NewRedisConnDb 建立Redis实际连接
func SessListJoin ¶
func SessListSplit ¶
Types ¶
type RedisContainer ¶
RedisContainer Redis容器,包括 *redis.Pool 和 *redisx.ConnMux 两个实现
type RedisHash ¶
type RedisHash struct { *RedisWrapper // contains filtered or unexported fields }
func NewRedisHash ¶
func NewRedisHash(r *RedisWrapper, name string, timeout int) *RedisHash
func (*RedisHash) GetTimeout ¶
GetTimeout 获取剩余时间 -1=无限 -2=不存在 -3=出错
func (*RedisHash) LoadForeignJson ¶
只能得到CacheData数据的Map,基本类型需要自己加载
func (*RedisHash) LoadForeignString ¶
func (*RedisHash) LoadMapInt ¶
func (*RedisHash) LoadMapString ¶
func (*RedisHash) LoadSummary ¶
func (*RedisHash) OrigDelete ¶ added in v1.6.0
func (*RedisHash) SaveForeignData ¶
基本类型保存于自身,CacheData数据关联保存为Json
type RedisWrapper ¶
type RedisWrapper struct { MaxIdleConn int // 最大空闲连接数 MaxIdleTime int // 最大空闲时长 RetryTimes int // 重试次数 MaxReadTime int // 命令最大执行时长(不算连接部分) RedisContainer }
RedisWrapper Redis包装器,给容器加上超时等参数
func NewRedisConnMux ¶
func NewRedisConnMux(conn redis.Conn, err error) *RedisWrapper
NewRedisConnMux 建立Redis连接复用
func NewRedisPool ¶
func NewRedisPool(cfg dialect.ConnConfig, maxIdle int) *RedisWrapper
NewRedisPool 建立Redis连接池
func (*RedisWrapper) Exec ¶
func (r *RedisWrapper) Exec(cmd string, args ...any) (any, error)
Exec 执行命令,将会重试几次
func (*RedisWrapper) Expire ¶
func (r *RedisWrapper) Expire(key string, timeout int) (bool, error)
Expire 设置键的过期时间
func (*RedisWrapper) Find ¶
func (r *RedisWrapper) Find(wildcard string) ([]string, error)
Find 模糊查找
func (*RedisWrapper) GetMaxReadDuration ¶
func (r *RedisWrapper) GetMaxReadDuration() time.Duration
GetMaxReadDuration 单命令最大执行时长(不算连接部分)
func (*RedisWrapper) GetTimeout ¶
func (r *RedisWrapper) GetTimeout(key string) int
GetTimeout -1=无限 -2=不存在 -3=出错
func (*RedisWrapper) IncrFloat ¶
func (r *RedisWrapper) IncrFloat(key string, offset float64) (float64, error)
计数增加
func (*RedisWrapper) IncrInt ¶
func (r *RedisWrapper) IncrInt(key string, offset int) (int, error)
计数增加
func (*RedisWrapper) IncrInt64 ¶
func (r *RedisWrapper) IncrInt64(key string, offset int64) (int64, error)
计数增加
func (*RedisWrapper) LoadMapInt ¶
func (r *RedisWrapper) LoadMapInt(keys ...string) (map[string]int, error)
func (*RedisWrapper) LoadMapString ¶
func (r *RedisWrapper) LoadMapString(keys ...string) (map[string]string, error)
func (*RedisWrapper) OrigDelete ¶ added in v1.6.0
func (r *RedisWrapper) OrigDelete(keys ...any) (int, error)
func (*RedisWrapper) OrigMulti ¶ added in v1.6.0
func (r *RedisWrapper) OrigMulti(cmd string, keys ...any) (any, error)
type Session ¶
type Session struct { *RedisHash // contains filtered or unexported fields }
会话
func (*Session) GetFlashes ¶
GetFlashes 数量n为最大取出多少条消息,-1表示所有消息
type SessionRegistry ¶
type SessionRegistry struct { Onlines *RedisHash *RedisWrapper // contains filtered or unexported fields }
func NewRegistry ¶
func NewRegistry(w *RedisWrapper) *SessionRegistry
func (*SessionRegistry) DelSession ¶
func (sr *SessionRegistry) DelSession(token string) bool
func (SessionRegistry) GetKey ¶
func (sr SessionRegistry) GetKey(token string) string
func (*SessionRegistry) GetSession ¶
func (sr *SessionRegistry) GetSession(token string, timeout int) *Session
Click to show internal directories.
Click to hide internal directories.