Documentation
¶
Overview ¶
Package drivers provides session store implementations.
Index ¶
- type MemoryStore
- func (s *MemoryStore) Close() error
- func (s *MemoryStore) Delete(_ context.Context, id string) error
- func (s *MemoryStore) Get(_ context.Context, id string) (map[string]any, error)
- func (s *MemoryStore) Regenerate(ctx context.Context, oldID string) (string, error)
- func (s *MemoryStore) Set(_ context.Context, id string, data map[string]any, ttl time.Duration) error
- type Redis
- func (r *Redis) Close() error
- func (r *Redis) Delete(ctx context.Context, id string) error
- func (r *Redis) Get(ctx context.Context, id string) (map[string]any, error)
- func (r *Redis) Regenerate(ctx context.Context, oldID string) (string, error)
- func (r *Redis) Set(ctx context.Context, id string, data map[string]any, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is a fast in-process session store backed by a sync.Map. It is the default session store in development and is suitable for single-node production. Use a database or Redis store for multi-node deployments.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a MemoryStore and starts the background eviction goroutine. Call Close when the store is no longer needed to stop it.
func (*MemoryStore) Close ¶
func (s *MemoryStore) Close() error
Close stops the background eviction goroutine and its ticker. It is safe to call multiple times. Wire it into application shutdown (e.g. defer store.Close()).
func (*MemoryStore) Regenerate ¶
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis is a session store backed by Redis, suitable for multi-node deployments where sessions must be shared across processes.
Sessions are stored as JSON under "oni:session:<id>" with a TTL equal to the session lifetime; every Save refreshes the TTL (sliding expiration). Note that JSON round-tripping means numeric session values come back as float64 and concrete types are flattened to their JSON forms.
func NewRedis ¶
NewRedis creates a Redis session store from a Redis URL, e.g. "redis://:password@localhost:6379/0". The connection is established lazily on first use; an invalid URL fails immediately.
func NewRedisFromClient ¶
NewRedisFromClient wraps an existing go-redis client, letting applications share one client between sessions, cache, and queues.
func (*Redis) Close ¶
Close closes the underlying Redis client. It is safe to call on stores built via NewRedisFromClient too — only do so once the client is no longer shared.
func (*Redis) Get ¶
Get returns the session data for id. A missing or expired key yields session.ErrNotFound (the Manager then issues a fresh session); transport errors are returned verbatim so callers can distinguish an outage from a logged-out user. Corrupt payloads are treated as not-found so a bad record self-heals into a fresh session instead of wedging the user.
func (*Redis) Regenerate ¶
Regenerate rotates the session ID, preserving data and remaining TTL. The new session is stored BEFORE the old one is deleted: if the store fails midway, the data still exists under at least one ID instead of being lost (same ordering as the memory driver).