session

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry added in v0.0.2

type Entry struct {
	WorkerID   string
	UserSub    string    // bound user identity; empty when OIDC is not configured
	LastAccess time.Time // updated on every proxy request; used for idle sweep
}

Entry holds the state for a single session.

type MemoryStore added in v0.0.3

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

MemoryStore is a concurrent in-memory implementation of Store.

func NewMemoryStore added in v0.0.3

func NewMemoryStore() *MemoryStore

func (*MemoryStore) CountForWorker added in v0.0.3

func (s *MemoryStore) CountForWorker(workerID string) int

func (*MemoryStore) CountForWorkers added in v0.0.3

func (s *MemoryStore) CountForWorkers(workerIDs []string) int

CountForWorkers returns the total session count across the given worker IDs.

func (*MemoryStore) Delete added in v0.0.3

func (s *MemoryStore) Delete(sessionID string)

func (*MemoryStore) DeleteByWorker added in v0.0.3

func (s *MemoryStore) DeleteByWorker(workerID string) int

DeleteByWorker removes all sessions mapped to the given worker. Linear scan — acceptable at max_workers = 100.

func (*MemoryStore) EntriesForWorker added in v0.0.3

func (s *MemoryStore) EntriesForWorker(workerID string) map[string]Entry

EntriesForWorker returns a snapshot of all sessions for a worker.

func (*MemoryStore) Get added in v0.0.3

func (s *MemoryStore) Get(sessionID string) (Entry, bool)

Get returns the entry for the given session ID.

func (*MemoryStore) RerouteWorker added in v0.0.3

func (s *MemoryStore) RerouteWorker(oldWorkerID, newWorkerID string) int

RerouteWorker reassigns all sessions from oldWorkerID to newWorkerID. Used by container transfer to migrate sessions to the new worker.

func (*MemoryStore) Set added in v0.0.3

func (s *MemoryStore) Set(sessionID string, entry Entry)

Set creates or replaces a session entry.

func (*MemoryStore) SweepIdle added in v0.0.3

func (s *MemoryStore) SweepIdle(maxAge time.Duration) int

SweepIdle removes sessions whose LastAccess is older than maxAge. Returns the number of sessions removed.

func (*MemoryStore) Touch added in v0.0.3

func (s *MemoryStore) Touch(sessionID string) bool

Touch updates the LastAccess timestamp for an existing session. Returns false if the session does not exist.

type RedisStore added in v0.0.3

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

RedisStore implements session.Store using Redis hashes.

Key schema:

{prefix}session:{sessionID}  ->  hash {worker_id, user_sub, last_access}

Each session key has a TTL equal to idleTTL. Touch refreshes it. SweepIdle is a no-op — Redis TTL expiry handles idle cleanup.

func NewRedisStore added in v0.0.3

func NewRedisStore(client *redisstate.Client, idleTTL time.Duration) *RedisStore

func (*RedisStore) CountForWorker added in v0.0.3

func (s *RedisStore) CountForWorker(workerID string) int

func (*RedisStore) CountForWorkers added in v0.0.3

func (s *RedisStore) CountForWorkers(workerIDs []string) int

func (*RedisStore) Delete added in v0.0.3

func (s *RedisStore) Delete(sessionID string)

func (*RedisStore) DeleteByWorker added in v0.0.3

func (s *RedisStore) DeleteByWorker(workerID string) int

func (*RedisStore) EntriesForWorker added in v0.0.3

func (s *RedisStore) EntriesForWorker(workerID string) map[string]Entry

func (*RedisStore) Get added in v0.0.3

func (s *RedisStore) Get(sessionID string) (Entry, bool)

func (*RedisStore) RerouteWorker added in v0.0.3

func (s *RedisStore) RerouteWorker(oldWorkerID, newWorkerID string) int

func (*RedisStore) Set added in v0.0.3

func (s *RedisStore) Set(sessionID string, entry Entry)

func (*RedisStore) SweepIdle added in v0.0.3

func (s *RedisStore) SweepIdle(_ time.Duration) int

SweepIdle is a no-op for Redis — TTL-based expiry handles idle cleanup.

func (*RedisStore) Touch added in v0.0.3

func (s *RedisStore) Touch(sessionID string) bool

type Store

type Store interface {
	Get(sessionID string) (Entry, bool)
	Set(sessionID string, entry Entry)
	Touch(sessionID string) bool
	Delete(sessionID string)
	DeleteByWorker(workerID string) int
	CountForWorker(workerID string) int
	CountForWorkers(workerIDs []string) int
	RerouteWorker(oldWorkerID, newWorkerID string) int
	EntriesForWorker(workerID string) map[string]Entry
	SweepIdle(maxAge time.Duration) int
}

Store defines the contract for session state storage. MemoryStore is the in-process implementation; Redis implements the same interface for shared state during rolling updates.

Jump to

Keyboard shortcuts

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