Distributed Session
createDistributedSession(redis, options?) is the Redis-backed counterpart to the adapter’s createSession plugin. Same API shape; swap the import to switch between in-process and cluster-wide.
Setup
import { createRedisClient } from 'svelte-adapter-uws-extensions/redis';
import { createDistributedSession } from 'svelte-adapter-uws-extensions/redis/session';
const redis = createRedisClient();
const sessions = createDistributedSession(redis, { ttlMs: 30 * 60_000 });
Usage
await sessions.set('user:42', { name: 'Alice', role: 'admin' });
const data = await sessions.get('user:42'); // refreshes TTL
await sessions.touch('user:42'); // refresh without reading
await sessions.delete('user:42');
API
| Method | Description |
|---|
get(key) | Returns the stored value or undefined. Refreshes TTL when refreshOnGet is true. |
set(key, value, opts?) | Store a value with optional per-call ttlMs override. |
delete(key) | Remove a key. |
touch(key) | Refresh the TTL without reading. |
clear() | Drop every entry under the configured prefix. |
Options
| Option | Default | Description |
|---|
ttlMs | 30 * 60_000 | Default time-to-live in ms. |
refreshOnGet | true | Whether get refreshes the TTL. |
prefix | 'session:' | Redis key prefix. |
Metrics
| Metric | Type | Labels |
|---|
session_get_total | counter | result: 'hit' \| 'miss' |
session_set_total | counter | - |
session_delete_total | counter | result: 'hit' \| 'miss' |
session_touch_total | counter | result: 'hit' \| 'miss' |
See also