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

MethodDescription
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

OptionDefaultDescription
ttlMs30 * 60_000Default time-to-live in ms.
refreshOnGettrueWhether get refreshes the TTL.
prefix'session:'Redis key prefix.

Metrics

MetricTypeLabels
session_get_totalcounterresult: 'hit' \| 'miss'
session_set_totalcounter-
session_delete_totalcounterresult: 'hit' \| 'miss'
session_touch_totalcounterresult: 'hit' \| 'miss'

See also

Was this page helpful?