Help us shape the future of Go! Take the 2026 Go Developer Survey

session

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 18 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Managers = map[string]Manager{}

Managers 已注册会话管理器

View Source
var Name string = "buntdb"

Name 默认为会话管理器

View Source
var SessionHandlers = map[string]process.Handler{
	"id":      processID,
	"get":     processGet,
	"del":     processDel,
	"set":     processSet,
	"dump":    processDump,
	"getmany": processGetMany,
	"setmany": processSetMany,
	"delmany": processDelMany,
}

SessionHandlers 模型运行器

View Source
var Timeout time.Duration = 3600 * time.Second

Timeout 默认有效时间

Functions

func ID

func ID() string

ID 生成SessionID

func Lang added in v0.10.3

func Lang(process *process.Process, defaults ...string) string

Lang get user language setting

func Register

func Register(name string, manger Manager)

Register 注册会话管理器

Types

type BuntDB

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

BuntDB BuntDB store

func NewBuntDB

func NewBuntDB(datafile string) (*BuntDB, error)

NewBuntDB create a new BuntDB instance

func (*BuntDB) Close

func (bunt *BuntDB) Close()

Close burndb connection

func (*BuntDB) Del added in v1.0.0

func (bunt *BuntDB) Del(id string, key string) error

Del session value

func (*BuntDB) Dump

func (bunt *BuntDB) Dump(id string) (map[string]interface{}, error)

Dump session data

func (*BuntDB) Get

func (bunt *BuntDB) Get(id string, key string) (interface{}, error)

Get session value

func (*BuntDB) Init

func (bunt *BuntDB) Init()

Init initialization

func (*BuntDB) Set

func (bunt *BuntDB) Set(id string, key string, value interface{}, timeout time.Duration) error

Set session value

type Manager

type Manager interface {
	Init()
	Set(id string, key string, value interface{}, expired time.Duration) error
	Get(id string, key string) (interface{}, error)
	Del(id string, key string) error
	Dump(id string) (map[string]interface{}, error)
}

Manager Session 管理器

type Redis

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

Redis session store

func NewRedis

func NewRedis(host string, options ...string) (*Redis, error)

NewRedis create a new redis instance host string, port int, db int, password string, username string, timeout int

func (*Redis) Del added in v1.0.0

func (redis *Redis) Del(id string, key string) error

Del session value

func (*Redis) Dump

func (redis *Redis) Dump(id string) (map[string]interface{}, error)

Dump session data

func (*Redis) Get

func (redis *Redis) Get(id string, key string) (interface{}, error)

Get session value

func (*Redis) Init

func (redis *Redis) Init()

Init initialization

func (*Redis) Set

func (redis *Redis) Set(id string, key string, value interface{}, timeout time.Duration) error

Set session value

type Session

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

Session 数据结构

func Global

func Global() *Session

Global 全局会话

func Use

func Use(name string) *Session

Use 选用会话管理器

func (*Session) AsGlobal

func (session *Session) AsGlobal() *Session

AsGlobal 设定为全局

func (*Session) Del added in v1.0.0

func (session *Session) Del(key string) error

Del 删除数值

func (*Session) Dump

func (session *Session) Dump() (map[string]interface{}, error)

Dump 导出所有数据

func (*Session) Expire

func (session *Session) Expire(expiredAt time.Duration) *Session

Expire 设定过期时间

func (*Session) Get

func (session *Session) Get(key string) (interface{}, error)

Get 读取数值

func (*Session) GetID

func (session *Session) GetID() string

GetID 读取 Session ID

func (*Session) ID

func (session *Session) ID(id string) *Session

ID 选择指定 Session ID

func (*Session) Make

func (session *Session) Make() *Session

Make 生成新的 Session ID

func (*Session) MustDel added in v1.0.0

func (session *Session) MustDel(key string)

MustDel 删除数值

func (*Session) MustDump

func (session *Session) MustDump() map[string]interface{}

MustDump 导出所有数据

func (*Session) MustGet

func (session *Session) MustGet(key string) interface{}

MustGet 读取数值

func (*Session) MustSet

func (session *Session) MustSet(key string, value interface{})

MustSet 设置数值

func (*Session) MustSetMany

func (session *Session) MustSetMany(values map[string]interface{})

MustSetMany 设置多个数值

func (*Session) MustSetManyWithEx

func (session *Session) MustSetManyWithEx(values map[string]interface{}, timeout time.Duration)

MustSetManyWithEx 设置多个数值

func (*Session) MustSetWithEx

func (session *Session) MustSetWithEx(key string, value interface{}, timeout time.Duration)

MustSetWithEx 设置数值

func (*Session) Set

func (session *Session) Set(key string, value interface{}) error

Set 设置数值

func (*Session) SetMany

func (session *Session) SetMany(values map[string]interface{}) error

SetMany 设置多个数值

func (*Session) SetManyWithEx

func (session *Session) SetManyWithEx(values map[string]interface{}, timeout time.Duration) error

SetManyWithEx 设置多个数值

func (*Session) SetWithEx

func (session *Session) SetWithEx(key string, value interface{}, timeout time.Duration) error

SetWithEx 设置数值

Jump to

Keyboard shortcuts

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