Skip to content

About

Redis backends for HTTPOk

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

httpok-redis

Optional Redis integration for github.com/candango/httpok.

The core httpok module owns the session contracts and does not depend on Redis. This module owns the Redis client and implements httpok/session.Store.

Generic usage

store, err := redisstore.New(
    redisstore.WithAddress("127.0.0.1:6379"),
    redisstore.WithDatabase(0),
    redisstore.WithPrefix("httpok:session"),
    redisstore.WithTTL(30*time.Minute),
)
if err != nil {
    return err
}

engine := session.NewStoreEngine(store)
if err := engine.Start(ctx); err != nil {
    return err
}
defer engine.Stop(ctx)

PHP/Firenado compatibility

The legacy PHP handler used by Firenado stores the complete session payload as JSON in Redis database 1 using keys shaped as GLOBAL_SESSION:<PHPSESSID>. Configure the adapter with the compatibility option:

store, err := redisstore.New(
    redisstore.WithPHPCompatibility(30 * time.Minute),
)

The PHP and Go applications must agree on the TTL. The cookie is the opaque PHPSESSID; no signing secret is required for this shared-cookie mode.

Set uses Redis native expiration atomically, and Touch refreshes the TTL without changing the JSON payload. Redis owns expiration, so RequiresPurge returns false.

For shared PHP sessions, configure the Go engine with the same cookie name and leave CookieSecret empty because the shared PHPSESSID is an opaque bearer ID. Configure the Redis adapter with WithPHPCompatibility(ttl) and use the same TTL in PHP's session handler. Cookie transport attributes must also match between applications, especially Path, Domain, Secure, and SameSite.

The PHP integration test uses a generic SessionHandlerInterface fixture and a TCP miniredis server. It verifies PHP-to-Go and Go-to-PHP JSON round trips, TTL assignment, and deletion without depending on an application-specific codebase.

Store contract and tests

The adapter implements the complete session.Store surface: lifecycle, byte/string reads and writes, existence checks, idempotent deletion, native expiration, touch, and purge capability reporting. It also exposes the legacy Read(id, any) helper provided by FileStore. Session IDs are validated before they become Redis keys; the default allowlist matches FileStore, while the PHP compatibility preset also accepts comma-separated PHP IDs.

Unit tests use miniredis, which is imported only by *_test.go files. It is not part of the production package dependency graph. The executable Go example in example_test.go verifies PHP-compatible session sharing through session.StoreEngine.

php -l testdata/php_session.php
go test ./...
go vet ./...
go test -race ./...

Compatibility

The module is validated against the published httpok session Store contract. Redis remains an optional dependency owned exclusively by this module.

About

Redis backends for HTTPOk

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages