session

package
v0.0.0-...-d80f745 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

管理session

func NewManager

func NewManager(cache *redis.Redis) *Manager

func (*Manager) GetSession

func (m *Manager) GetSession(ctx context.Context, sessId string) (*model.Session, error)

Get 获取Session

返回的Session已经进行了过期检查

func (*Manager) GetUserSessions

func (m *Manager) GetUserSessions(ctx context.Context, uid uint64) ([]*model.Session, error)

GetUserSessions 获取某个用户的所有session

返回的Session已经经过了过期检查

func (*Manager) InvalidateAll

func (m *Manager) InvalidateAll(ctx context.Context, uid uint64) error

令某个用户的所有session立即失效

func (*Manager) InvalidateSession

func (m *Manager) InvalidateSession(ctx context.Context, sessId string) error

立即令session过期

func (*Manager) MarshalUserBase

func (m *Manager) MarshalUserBase(user *dao.UserBase) (string, error)

func (*Manager) NewSession

func (m *Manager) NewSession(ctx context.Context, user *dao.UserBase, platform string) (*model.Session, error)

创建新的session并且保存

func (*Manager) RenewSession

func (m *Manager) RenewSession(ctx context.Context, sessId string) error

给一个已经存在的session续期

func (*Manager) UnmarshalUserBase

func (m *Manager) UnmarshalUserBase(data string) (*dao.UserBase, error)

type RedisStore

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

func (*RedisStore) BatchDel

func (r *RedisStore) BatchDel(ctx context.Context, keys []string) error

func (*RedisStore) BatchGet

func (r *RedisStore) BatchGet(ctx context.Context, keys []string) ([]*model.Session, error)

func (*RedisStore) Del

func (r *RedisStore) Del(ctx context.Context, key string) error

func (*RedisStore) DelUid

func (r *RedisStore) DelUid(ctx context.Context, uid uint64) error

func (*RedisStore) Get

func (r *RedisStore) Get(ctx context.Context, key string) (sess *model.Session, found bool, err error)

func (*RedisStore) GetUid

func (r *RedisStore) GetUid(ctx context.Context, uid uint64) ([]*model.Session, error)

func (*RedisStore) Set

func (r *RedisStore) Set(ctx context.Context, key string, sess *model.Session) error

type RedisStoreOpt

type RedisStoreOpt func(*RedisStore)

func WithSerializer

func WithSerializer(ser model.SessionSerializer) RedisStoreOpt

func WithSessPrefix

func WithSessPrefix(px string) RedisStoreOpt

func WithUidPrefix

func WithUidPrefix(px string) RedisStoreOpt

type Store

type Store interface {
	// 获取id为key的session
	// 返回找到的session, 如果found为true, 表示没有对应的key的session
	// err不为nil时, 表示发生了系统错误
	Get(ctx context.Context, key string) (sess *model.Session, found bool, err error)
	// 批量获取
	BatchGet(ctx context.Context, keys []string) ([]*model.Session, error)
	// 获取uid所有的session
	GetUid(ctx context.Context, uid uint64) ([]*model.Session, error)
	// 设置id为key的session 存在则覆盖
	Set(ctx context.Context, key string, sess *model.Session) error
	// 立即删除id为key的session, 如果不存在 则操作为no-op
	Del(ctx context.Context, key string) error
	// 批量删除sessId
	BatchDel(ctx context.Context, keys []string) error
	// 删除uid的所有session, 如果不存在, 则操作为no-op
	DelUid(ctx context.Context, uid uint64) error
}

Store只提供存储功能

func NewRedisStore

func NewRedisStore(cache *redis.Redis, opts ...RedisStoreOpt) Store

Jump to

Keyboard shortcuts

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