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
// PhaseHook, when non-nil, is invoked with a short tag at each
// significant step of New() / ensureSchema(). Tags:
//
// ensure_schema:begin_tx — pool.BeginTx() about to run
// ensure_schema:set_lock_timeout — SET LOCAL lock_timeout
// ensure_schema:acquire_lock — pg_advisory_xact_lock
// ensure_schema:lock_acquired — lock now held
// ensure_schema:check_table — pg_class lookup for the table
// ensure_schema:create_table — CREATE TABLE (only on bootstrap)
// ensure_schema:check_index — pg_class lookup for the index
// ensure_schema:create_index — CREATE INDEX (only on bootstrap)
// ensure_schema:commit — tx.Commit() about to run
// ensure_schema:done — committed cleanly
//
// Used by diagnostic harnesses (probatorium matrix nightly) to
// pinpoint which step blocks under pathological contention. The
// hook MUST NOT block — it runs inline on the schema-init path
// and is called with no locks held but on the same goroutine as
// the SQL operations. Production deployments leave this nil.
PhaseHook func(phase string)
}
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".