fix(redis): paginate stream entries

This commit is contained in:
onenewcode authored and GitHub committed 2026-07-30 15:56:56 +08:00
1 parent 7775bbf8f8
commit 223e9b3a2f
21 files changed
+479 -33

No files matched your search

@@ -146,6 +146,38 @@ describe("redisValuePresentation", () => {
}`);
});
it("uses the Stream's Redis length instead of the loaded page size", () => {
const value = {
key_display: "orders",
key_raw: "b3JkZXJz",
ttl: -1,
redis_type: "stream",
data: {
kind: "stream" as const,
entries: [{ id: "1714470000000-0", fields: [{ field: "event", value: "login" }] }],
total: 177,
next_cursor: "1714470000000-0",
},
};
expect(redisValueSize(value)).toBe(177);
});
it("uses loaded Stream entries when the total is unavailable", () => {
const value = {
key_display: "orders",
key_raw: "b3JkZXJz",
ttl: -1,
redis_type: "stream",
data: {
kind: "stream" as const,
entries: [{ id: "1714470000000-0", fields: [{ field: "event", value: "login" }] }],
},
};
expect(redisValueSize(value)).toBe(1);
});
it("labels raw text views by encoding instead of generic raw text", () => {
expect(formatRedisMemberDetail("plain-text").rawLabel).toBe("ASCII");
expect(
+2
View File
@@ -392,6 +392,7 @@ export const redisScanKeys = forward("redisScanKeys");
export const redisScanKeysBatch = forward("redisScanKeysBatch");
export const redisScanValues = forward("redisScanValues");
export const redisGetValue = forward("redisGetValue");
export const redisGetStreamEntries = forward("redisGetStreamEntries");
export const redisGetStreamGroups = forward("redisGetStreamGroups");
export const redisGetStreamConsumers = forward("redisGetStreamConsumers");
export const redisGetStreamPending = forward("redisGetStreamPending");
@@ -640,6 +641,7 @@ export type {
RedisStreamField,
RedisStreamGroup,
RedisStreamMetric,
RedisStreamPage,
RedisStreamPendingEntry,
RedisStreamPendingPage,
RedisValue,
+5
View File
@@ -70,6 +70,7 @@ import type {
RedisDatabaseInfo,
RedisStreamConsumer,
RedisStreamGroup,
RedisStreamPage,
RedisStreamPendingPage,
RedisValue,
RedisScanResult,
@@ -2253,6 +2254,10 @@ export async function redisGetValue(connectionId: string, db: number, keyRaw: st
return post("/api/redis/get-value", { connectionId, db, keyRaw });
}
export async function redisGetStreamEntries(connectionId: string, db: number, keyRaw: string, cursor?: string): Promise<RedisStreamPage> {
return post("/api/redis/get-stream-entries", { connectionId, db, keyRaw, cursor });
}
export async function redisGetStreamGroups(connectionId: string, db: number, keyRaw: string): Promise<RedisStreamGroup[]> {
return post("/api/redis/get-stream-groups", { connectionId, db, keyRaw });
}
+10 -1
View File
@@ -1949,6 +1949,11 @@ export interface RedisStreamEntry {
fields: RedisStreamField[];
}
export interface RedisStreamPage {
entries: RedisStreamEntry[];
next_cursor?: string;
}
// Redis counters above Number.MAX_SAFE_INTEGER are transported as decimal strings.
export type RedisStreamMetric = number | string;
@@ -2002,7 +2007,7 @@ export type RedisValueData =
total: number;
scan_cursor?: number;
}
| { kind: "stream"; entries: RedisStreamEntry[] }
| { kind: "stream"; entries: RedisStreamEntry[]; total?: number; next_cursor?: string }
| { kind: "unknown" };
export interface RedisValue {
@@ -2085,6 +2090,10 @@ export async function redisGetValue(connectionId: string, db: number, keyRaw: st
return invoke("redis_get_value", { connectionId, db, keyRaw });
}
export async function redisGetStreamEntries(connectionId: string, db: number, keyRaw: string, cursor?: string): Promise<RedisStreamPage> {
return invoke("redis_get_stream_entries", { connectionId, db, keyRaw, cursor });
}
export async function redisGetStreamGroups(connectionId: string, db: number, keyRaw: string): Promise<RedisStreamGroup[]> {
return invoke("redis_get_stream_groups", { connectionId, db, keyRaw });
}
@@ -327,7 +327,7 @@ export function redisValueSize(value: RedisValue): number {
case "zset":
return value.data.total;
case "stream":
return value.data.entries.length;
return value.data.total ?? value.data.entries.length;
default:
return 0;
}