Documentation ¶
Overview ¶
Package session 实现了基于内存的session管理功能
Index ¶
- func Register(kind string, creator SessionContainerCreator) error
- type Error
- type MemSession
- func (this *MemSession) Bool(key string) (bool, bool)
- func (this *MemSession) Dead() bool
- func (this *MemSession) Deadline() int
- func (this *MemSession) Delete(key string)
- func (this *MemSession) Die()
- func (this *MemSession) Float(key string) (float64, bool)
- func (this *MemSession) Int(key string) (int, bool)
- func (this *MemSession) SessionId() string
- func (this *MemSession) SetBool(key string, value bool)
- func (this *MemSession) SetDeadline(second int)
- func (this *MemSession) SetFloat(key string, value float64)
- func (this *MemSession) SetInt(key string, value int)
- func (this *MemSession) SetString(key string, value string)
- func (this *MemSession) SetValue(key string, value interface{})
- func (this *MemSession) String(key string) (string, bool)
- func (this *MemSession) Value(key string) (interface{}, bool)
- type MemSessionContainer
- type Session
- type SessionContainer
- type SessionContainerCreator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(kind string, creator SessionContainerCreator) error
Register 注册SessionContainer创建器
Types ¶
type Error ¶
type Error string
错误信息
type MemSession ¶
type MemSession struct {
// contains filtered or unexported fields
}
内存Session,每次操作都会使Session有效时间延长
func (*MemSession) SetBool ¶
func (this *MemSession) SetBool(key string, value bool)
SetBool 设置bool值
func (*MemSession) SetDeadline ¶
func (this *MemSession) SetDeadline(second int)
SetDeadline 设置有效期限
second:从当前时间开始有效的秒数
func (*MemSession) SetFloat ¶
func (this *MemSession) SetFloat(key string, value float64)
SetFloat 设置浮点值
func (*MemSession) SetString ¶
func (this *MemSession) SetString(key string, value string)
SetString 设置字符串
func (*MemSession) SetValue ¶
func (this *MemSession) SetValue(key string, value interface{})
SetValue 设置值
type MemSessionContainer ¶
type MemSessionContainer struct {
// contains filtered or unexported fields
}
内存Session容器
func (*MemSessionContainer) Clean ¶
func (this *MemSessionContainer) Clean() int
Clean 清理过期Session 并返回清理的数量
func (*MemSessionContainer) Close ¶
func (this *MemSessionContainer) Close()
Close 关闭SessionProvider,关闭之后将无法使用
func (*MemSessionContainer) Closed ¶
func (this *MemSessionContainer) Closed() bool
Closed 确认当前SessionProvider是否已经关闭
func (*MemSessionContainer) CreateSession ¶
func (this *MemSessionContainer) CreateSession() (Session, bool)
CreateSession 创建Session
type Session ¶
type Session interface { // SessionId 返回Session的Id SessionId() string // Value 获取值 Value(key string) (interface{}, bool) // String 获取字符串 String(key string) (string, bool) // Int 获取整数值 Int(key string) (int, bool) // Bool 获取bool值 Bool(key string) (bool, bool) // Float 获取浮点值 Float(key string) (float64, bool) // SetValue 设置值 SetValue(key string, value interface{}) // SetString 设置字符串 SetString(key string, value string) // SetInt 设置整数值 SetInt(key string, value int) // SetBool 设置bool值 SetBool(key string, value bool) // SetFloat 设置浮点值 SetFloat(key string, value float64) // Delete 删除指定键 Delete(key string) // SetDeadline 设置有效期限 SetDeadline(second int) // Deadline 获取过期时间 Deadline() int // Dead 让Session立即过期 Die() // Dead 判断Session是否过期 Dead() bool }
Session
type SessionContainer ¶
type SessionContainer interface { // CreateSession 创建Session CreateSession() (Session, bool) // Session 获取Session Session(sessionId string) (Session, bool) // Close 关闭SessionProvider,关闭之后将无法使用 Close() // Closed 确认当前SessionProvider是否已经关闭 Closed() bool }
Session容器
func NewMemSessionContainer ¶
func NewMemSessionContainer(expire int, source string) (SessionContainer, error)
NewMemSessionContainer 创建Session提供器(数据存储在内存中,source参数无效)
func NewSessionContainer ¶
func NewSessionContainer(kind string, expire int, source string) (SessionContainer, error)
NewSessionContainer 创建一个新的Session容器
expire:最大过期时间(秒)
type SessionContainerCreator ¶
type SessionContainerCreator func(expire int, source string) (SessionContainer, error)
SessionContainer创建器
expire:session有效期 source:存储源
Click to show internal directories.
Click to hide internal directories.