Documentation
¶
Overview ¶
Package postgresstore provides a store.KV session backend built on the native celeris driver/postgres client. Sessions are persisted as BYTEA values under a configurable table (default "celeris_sessions").
The schema is created on first New call if it does not exist. A background cleanup goroutine periodically removes expired rows. Call Store.Close to stop the goroutine in tests or graceful shutdown paths.
TLS: driver/postgres does not yet support sslmode=require; use sslmode=disable on loopback / VPC deployments.
Index ¶
- type Options
- type Store
- func (s *Store) Close() error
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) DeletePrefix(ctx context.Context, prefix string) error
- func (s *Store) Get(ctx context.Context, key string) ([]byte, error)
- func (s *Store) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// TableName is the target table. Default: "celeris_sessions".
TableName string
// CleanupInterval is how often expired rows are removed. Default:
// 5 minutes. Zero disables cleanup entirely (rows still expire on
// Get, but the table grows unbounded with never-read keys).
CleanupInterval time.Duration
// CleanupContext, when set, cancels the cleanup goroutine when
// the context is done. If nil, Close is the only way to stop the
// goroutine.
CleanupContext context.Context
// SkipSchemaInit, when true, suppresses the CREATE TABLE IF NOT
// EXISTS statement issued by New. Use this when the DBA has
// provisioned the schema out-of-band or the role does not have
// DDL privileges.
SkipSchemaInit bool
}
Options configure the PostgreSQL-backed session store.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a store.KV backed by a PostgreSQL table. Implements store.PrefixDeleter via TRUNCATE (empty prefix clears the table).
func New ¶
New creates a PostgreSQL-backed session store. The schema is auto-initialized on first call unless [Options.SkipSchemaInit] is true. A background cleanup goroutine is started if [Options.CleanupInterval] > 0.
func (*Store) DeletePrefix ¶
DeletePrefix implements store.PrefixDeleter. An empty prefix TRUNCATEs the table; any other prefix runs a DELETE with a LIKE predicate. Prefix characters are escaped to avoid LIKE wildcards being interpreted.
func (*Store) Set ¶
Set implements store.KV. A ttl <= 0 stores NULL for expires_at (no expiry). Positive ttl converts to NOW() + INTERVAL.
Expires is passed as either a time.Time (positive TTL) or nil (no expiry). The celeris-postgres driver accepts those forms natively; passing sql.NullTime would fail with "unsupported argument type".