Skip to content

@codesoul-co/hypha-memory / memory-server-redis-migration

模块用法

用于使用该功能边界的公共契约与操作。Memory server redis migration 模块公开 1 类、1 函数、7 接口。

从包入口导入

ts
import {
  RedisStreamWorkingMemoryMigrationAdapter,
  scanRedisWorkingMemoryKeys,
} from '@codesoul-co/hypha-memory';

import type {
  RedisScanBudget,
  RedisScanReport,
  RedisStreamMigrationClient,
  RedisStreamWorkingMemoryMigrationAdapterOptions,
  WorkingMemoryMigrationAppend,
  WorkingMemoryMigrationEntry,
  WorkingMemoryMigrationPort,
} from '@codesoul-co/hypha-memory';

使用要点

  • 7 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 1 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
  • 1 个函数是该模块的直接操作入口;每个 overload 的必需/可选参数与返回类型均在下方列出。

公共导出

Symbol种类签名说明
RedisStreamWorkingMemoryMigrationAdapternew RedisStreamWorkingMemoryMigrationAdapter(options: RedisStreamWorkingMemoryMigrationAdapterOptions): RedisStreamWorkingMemoryMigrationAdapterRedis Stream adapter used by dev to execute the Framework-owned migration acceptance suite.
scanRedisWorkingMemoryKeys函数scanRedisWorkingMemoryKeys(client: Pick<RedisStreamMigrationClient, "scan">, pattern: string, budget?: RedisScanBudget, nowMs?: () => number): Promise<RedisScanReport>Scan Redis Working Memory Keys 函数,提供 1 个公开调用签名;参数与返回类型见下表。
RedisScanBudget接口interface RedisScanBudgetRedis Scan Budget 接口,共包含 4 个公开字段或方法。
RedisScanReport接口interface RedisScanReportRedis Scan Report 接口,共包含 3 个公开字段或方法。
RedisStreamMigrationClient接口interface RedisStreamMigrationClientRedis Stream Migration Client 接口,共包含 6 个公开字段或方法。
RedisStreamWorkingMemoryMigrationAdapterOptions接口interface RedisStreamWorkingMemoryMigrationAdapterOptionsRedis Stream Working Memory Migration Adapter Options 接口,共包含 4 个公开字段或方法。
WorkingMemoryMigrationAppend接口interface WorkingMemoryMigrationAppendWorking Memory Migration Append 接口,共包含 5 个公开字段或方法。
WorkingMemoryMigrationEntry接口interface WorkingMemoryMigrationEntryWorking Memory Migration Entry 接口,共包含 4 个公开字段或方法。
WorkingMemoryMigrationPort接口interface WorkingMemoryMigrationPortWorking Memory Migration Port 接口,共包含 4 个公开字段或方法。

RedisStreamWorkingMemoryMigrationAdapter

Redis Stream adapter used by dev to execute the Framework-owned migration acceptance suite.

  • 种类: 类
  • 导入: import { RedisStreamWorkingMemoryMigrationAdapter } from '@codesoul-co/hypha-memory';
  • 源码模块: memory-server-redis-migration

声明

text
export declare class RedisStreamWorkingMemoryMigrationAdapter implements WorkingMemoryMigrationPort {
    constructor(options: RedisStreamWorkingMemoryMigrationAdapterOptions);
    append<TValue = unknown>(input: WorkingMemoryMigrationAppend<TValue>): Promise<void>;
    list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryMigrationEntry<TValue>>>;
    latest<TValue = unknown>(scope: ManagedMemoryScope): Promise<WorkingMemoryMigrationEntry<TValue> | null>;
    clearScope(scope: ManagedMemoryScope, budget?: Partial<RedisScanBudget>): Promise<RedisScanReport>;
}

公开成员

成员种类签名说明
append方法append<TValue = unknown>(input: WorkingMemoryMigrationAppend<TValue>): Promise<void>公开方法;参数与返回类型以签名列为准。
clearScope方法clearScope(scope: ManagedMemoryScope, budget?: Partial<RedisScanBudget>): Promise<RedisScanReport>公开方法;参数与返回类型以签名列为准。
constructor构造函数(options: RedisStreamWorkingMemoryMigrationAdapterOptions): RedisStreamWorkingMemoryMigrationAdapter创建该类的实例。
latest方法latest<TValue = unknown>(scope: ManagedMemoryScope): Promise<WorkingMemoryMigrationEntry<TValue> | null>公开方法;参数与返回类型以签名列为准。
list方法list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryMigrationEntry<TValue>>>公开方法;参数与返回类型以签名列为准。

scanRedisWorkingMemoryKeys

Scan Redis Working Memory Keys 函数,提供 1 个公开调用签名;参数与返回类型见下表。

声明

text
export declare function scanRedisWorkingMemoryKeys(client: Pick<RedisStreamMigrationClient, 'scan'>, pattern: string, budget?: RedisScanBudget, nowMs?: () => number): Promise<RedisScanReport>;

调用签名

text
scanRedisWorkingMemoryKeys(client: Pick<RedisStreamMigrationClient, "scan">, pattern: string, budget?: RedisScanBudget, nowMs?: () => number): Promise<RedisScanReport>

参数

参数类型必需说明
clientPick<RedisStreamMigrationClient, "scan">必需参数;接受的值由类型列定义。
patternstring必需参数;接受的值由类型列定义。
budgetRedisScanBudget可选参数;接受的值由类型列定义。
nowMs() => number可选参数;接受的值由类型列定义。

返回值

  • 类型: Promise<RedisScanReport>
  • 说明: 返回值契约由上述类型定义。

RedisScanBudget

Redis Scan Budget 接口,共包含 4 个公开字段或方法。

声明

text
export interface RedisScanBudget {
    maxCalls: number;
    maxItems: number;
    maxDurationMs: number;
    count: number;
}

契约成员

成员种类签名说明
count属性count: number公开属性;类型、只读和可选状态以签名列为准。
maxCalls属性maxCalls: number公开属性;类型、只读和可选状态以签名列为准。
maxDurationMs属性maxDurationMs: number公开属性;类型、只读和可选状态以签名列为准。
maxItems属性maxItems: number公开属性;类型、只读和可选状态以签名列为准。

RedisScanReport

Redis Scan Report 接口,共包含 3 个公开字段或方法。

声明

text
export interface RedisScanReport {
    keys: string[];
    calls: number;
    terminated: boolean;
}

契约成员

成员种类签名说明
calls属性calls: number公开属性;类型、只读和可选状态以签名列为准。
keys属性keys: string[]公开属性;类型、只读和可选状态以签名列为准。
terminated属性terminated: boolean公开属性;类型、只读和可选状态以签名列为准。

RedisStreamMigrationClient

Redis Stream Migration Client 接口,共包含 6 个公开字段或方法。

声明

text
export interface RedisStreamMigrationClient {
    xadd(key: string, id: '*', field: 'entry', value: string): Promise<string | null>;
    xtrim(key: string, strategy: 'MAXLEN', threshold: number): Promise<number>;
    xrange(key: string, start: '-', end: '+'): Promise<Array<[string, string[]]>>;
    xrevrange(key: string, end: '+', start: '-', countToken: 'COUNT', count: 1): Promise<Array<[string, string[]]>>;
    scan(cursor: string, matchToken: 'MATCH', pattern: string, countToken: 'COUNT', count: number): Promise<[string, string[]]>;
    del(...keys: string[]): Promise<number>;
}

契约成员

成员种类签名说明
del方法del(...keys: string[]): Promise<number>公开方法;参数与返回类型以签名列为准。
scan方法scan(cursor: string, matchToken: "MATCH", pattern: string, countToken: "COUNT", count: number): Promise<[string, string[]]>公开方法;参数与返回类型以签名列为准。
xadd方法xadd(key: string, id: "*", field: "entry", value: string): Promise<string | null>公开方法;参数与返回类型以签名列为准。
xrange方法xrange(key: string, start: "-", end: "+"): Promise<Array<[string, string[]]>>公开方法;参数与返回类型以签名列为准。
xrevrange方法xrevrange(key: string, end: "+", start: "-", countToken: "COUNT", count: 1): Promise<Array<[string, string[]]>>公开方法;参数与返回类型以签名列为准。
xtrim方法xtrim(key: string, strategy: "MAXLEN", threshold: number): Promise<number>公开方法;参数与返回类型以签名列为准。

RedisStreamWorkingMemoryMigrationAdapterOptions

Redis Stream Working Memory Migration Adapter Options 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RedisStreamWorkingMemoryMigrationAdapterOptions } from '@codesoul-co/hypha-memory';
  • 源码模块: memory-server-redis-migration

声明

text
export interface RedisStreamWorkingMemoryMigrationAdapterOptions {
    client: RedisStreamMigrationClient;
    namespace?: string;
    scanBudget?: Partial<RedisScanBudget>;
    nowMs?: () => number;
}

契约成员

成员种类签名说明
client属性client: RedisStreamMigrationClient公开属性;类型、只读和可选状态以签名列为准。
namespace属性namespace?: string公开属性;类型、只读和可选状态以签名列为准。
nowMs方法nowMs?(): number公开方法;参数与返回类型以签名列为准。
scanBudget属性scanBudget?: Partial<RedisScanBudget>公开属性;类型、只读和可选状态以签名列为准。

WorkingMemoryMigrationAppend

Working Memory Migration Append 接口,共包含 5 个公开字段或方法。

声明

text
export interface WorkingMemoryMigrationAppend<TValue = unknown> {
    id: string;
    scope: ManagedMemoryScope;
    value: TValue;
    createdAt: string;
    maxMessages: number;
}

契约成员

成员种类签名说明
createdAt属性createdAt: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
maxMessages属性maxMessages: number公开属性;类型、只读和可选状态以签名列为准。
scope属性scope: ManagedMemoryScope公开属性;类型、只读和可选状态以签名列为准。
value属性value: TValue公开属性;类型、只读和可选状态以签名列为准。

WorkingMemoryMigrationEntry

Working Memory Migration Entry 接口,共包含 4 个公开字段或方法。

声明

text
export interface WorkingMemoryMigrationEntry<TValue = unknown> {
    id: string;
    scopeHash: string;
    value: TValue;
    createdAt: string;
}

契约成员

成员种类签名说明
createdAt属性createdAt: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
scopeHash属性scopeHash: string公开属性;类型、只读和可选状态以签名列为准。
value属性value: TValue公开属性;类型、只读和可选状态以签名列为准。

WorkingMemoryMigrationPort

Working Memory Migration Port 接口,共包含 4 个公开字段或方法。

声明

text
export interface WorkingMemoryMigrationPort {
    append<TValue = unknown>(input: WorkingMemoryMigrationAppend<TValue>): Promise<void>;
    list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryMigrationEntry<TValue>>>;
    latest<TValue = unknown>(scope: ManagedMemoryScope): Promise<WorkingMemoryMigrationEntry<TValue> | null>;
    clearScope(scope: ManagedMemoryScope, budget?: Partial<RedisScanBudget>): Promise<RedisScanReport>;
}

契约成员

成员种类签名说明
append方法append<TValue = unknown>(input: WorkingMemoryMigrationAppend<TValue>): Promise<void>公开方法;参数与返回类型以签名列为准。
clearScope方法clearScope(scope: ManagedMemoryScope, budget?: Partial<RedisScanBudget>): Promise<RedisScanReport>公开方法;参数与返回类型以签名列为准。
latest方法latest<TValue = unknown>(scope: ManagedMemoryScope): Promise<WorkingMemoryMigrationEntry<TValue> | null>公开方法;参数与返回类型以签名列为准。
list方法list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryMigrationEntry<TValue>>>公开方法;参数与返回类型以签名列为准。