RedisSessionClient
interfaz
Interfaz mínima de un cliente Redis para RedisSessionStore: get, set con PX, del y
eval. node-redis 4 o posterior la cumple; también un adaptador sobre la API REST de Upstash.
ts
import type { RedisSessionClient } from "@meekojs/meeko/server";Source code src/server/runtime/session-stores.ts:32
Declaración #
ts
interface RedisSessionClient {
get(key: string): Promise<string | null>
set(key: string, value: string, options: { PX: number }): Promise<unknown>
del(key: string): Promise<unknown>
eval(script: string, options: { keys: string[]; arguments: string[] }): Promise<unknown>
quit?(): Promise<unknown>
}Example #
ts
import type { RedisSessionClient } from "@meekojs/meeko/server";
function upstashClient(url: string, token: string): RedisSessionClient {
const command = async (...args: Array<string | number>): Promise<unknown> => {
const response = await fetch(url, { method: "POST", headers: { authorization: `Bearer ${token}` }, body: JSON.stringify(args) });
return ((await response.json()) as { result?: unknown }).result;
};
return {
get: async (key) => (await command("GET", key)) as string | null,
set: (key, value, { PX }) => command("SET", key, value, "PX", PX),
del: (key) => command("DEL", key),
eval: (script, { keys, arguments: args }) => command("EVAL", script, keys.length, ...keys, ...args),
};
}Miembros #
set
#
set(key: string, value: string, options: { PX: number }): Promise<unknown>Escribe una clave con caducidad en milisegundos.
eval
#
eval(script: string, options: { keys: string[]; arguments: string[] }): Promise<unknown>Ejecuta un script Lua de forma atómica.
See also #
- Redis through the Upstash REST API Framework full-stack