Saltar al contenido
Meeko
Escribe para buscar en las guías y en la referencia de la API. Ábrela desde cualquier página con / o Ctrl K; muévete con las flechas y entra con Intro.
Empezar

Contenidos

En esta página

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";

Código fuente 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>
}

Ejemplo #

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 #

get #

método

get(key: string): Promise<string | null>

Lee una clave, o null si no existe.

set #

método

set(key: string, value: string, options: { PX: number }): Promise<unknown>

Escribe una clave con caducidad en milisegundos.

del #

método

del(key: string): Promise<unknown>

Borra una clave.

eval #

método

eval(script: string, options: { keys: string[]; arguments: string[] }): Promise<unknown>

Ejecuta un script Lua de forma atómica.

quit #

método opcional

quit?(): Promise<unknown>

Cierra la conexión; sólo se usa con closeClient.

Véase también #

¿Te sirvió esta página?

Añadir un comentario

Se envía al elegir «Sí» o «No». Solo se guardan la página, tu respuesta y el comentario: ni cookies ni datos tuyos.

0 de 2000 caracteres

Editar en GitHub: packages/meeko/src/server/runtime/session-stores.ts