session

package
v0.0.0-...-82862be Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MemoryStore    = "memory"
	RedisStore     = "redis"
	MemcachedStore = "memcached"
)

Variables

This section is empty.

Functions

func NewSessionId

func NewSessionId() string

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func Default

func Default() *Manager

func New

func New(ttl time.Duration, store string) *Manager

func (*Manager) GetStore

func (manager *Manager) GetStore() Store

func (*Manager) NewSession

func (manager *Manager) NewSession() *Session

type MemStore

type MemStore struct {
	*concurrent.Map[string, *Session]
	// contains filtered or unexported fields
}

MemStore 内存中存储session,只适用于单节点应用

func (*MemStore) ActiveCount

func (store *MemStore) ActiveCount() int

ActiveCount 统计当前有效的session数量 ,并且同时会清理过期的session

func (*MemStore) CleanExpire

func (store *MemStore) CleanExpire()

CleanExpire 清理过期session

func (*MemStore) GetSession

func (store *MemStore) GetSession(sessionId string) *Session

GetSession 获取session,如果已经过期那么返回一个空

func (*MemStore) RemoveSession

func (store *MemStore) RemoveSession(sessionId ...string)

RemoveSession 移除会话

func (*MemStore) SaveSession

func (store *MemStore) SaveSession(sessionId string, session *Session)

SaveSession 存取session

func (*MemStore) SessionExist

func (store *MemStore) SessionExist(sessionId string) bool

SessionExist 会话是否存在

type Session

type Session struct {
	// contains filtered or unexported fields
}

func (*Session) ClearState

func (s *Session) ClearState()

func (*Session) Get

func (s *Session) Get(name string) any

func (*Session) GetAll

func (s *Session) GetAll() map[string]any

func (*Session) GetId

func (s *Session) GetId() string

func (*Session) IsDirty

func (s *Session) IsDirty() bool

func (*Session) IsExpire

func (s *Session) IsExpire() bool

func (*Session) IsNew

func (s *Session) IsNew() bool

func (*Session) Remove

func (s *Session) Remove(name string)

func (*Session) Save

func (s *Session) Save()

func (*Session) Set

func (s *Session) Set(name string, value any)

func (*Session) SetMap

func (s *Session) SetMap(data map[string]any)

type Store

type Store interface {
	SaveSession(sessionId string, session *Session)
	GetSession(sessionId string) *Session
	SessionExist(sessionId string) bool
	RemoveSession(sessionId ...string)
	ActiveCount() int
	CleanExpire()
}

func NewStore

func NewStore(store string, ttl time.Duration) Store

Jump to

Keyboard shortcuts

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