KeyValueClient
The subset of a Redis-like client the key-value adapter uses.
The subset of a Redis-like client the key-value adapter uses. A node-redis or ioredis client
satisfies it with thin wrappers (sAdd, sRem, sMembers, del, get, and set with a
millisecond expiry). createFakeKeyValue is a test double with the same semantics.
Import#
ts
import type { KeyValueClient } from "@shadow-js/dusk/server";
Signature#
ts
interface KeyValueClient {
/** The string at `key`, or `null`. */
get(key: string): Promise<string | null>;
/** Stores a string; `pxExpire` is the lifetime in milliseconds. */
set(key: string, value: string, options?: { readonly pxExpire?: number }): Promise<unknown>;
/** Removes keys; returns how many existed. */
del(key: string): Promise<number>;
/** Adds a member to a set; returns 1 when it was new. */
sAdd(key: string, member: string): Promise<number>;
/** Removes a member from a set; returns 1 when it was there. */
sRem(key: string, member: string): Promise<number>;
/** The members of a set (empty when the key is missing). */
sMembers(key: string): Promise<string[]>;
}
Members#
| Name | Type | Description |
|---|---|---|
get |
get(key: string): Promise<string | null> |
The string at key, or null. |
set |
set(key: string, value: string, options?: { readonly pxExpire?: number }): Promise<unknown> |
Stores a string; pxExpire is the lifetime in milliseconds. |
del |
del(key: string): Promise<number> |
Removes keys; returns how many existed. |
sAdd |
sAdd(key: string, member: string): Promise<number> |
Adds a member to a set; returns 1 when it was new. |
sRem |
sRem(key: string, member: string): Promise<number> |
Removes a member from a set; returns 1 when it was there. |
sMembers |
sMembers(key: string): Promise<string[]> |
The members of a set (empty when the key is missing). |