Skip to content

Commit

Permalink
bring all modules / all commands into v5
Browse files Browse the repository at this point in the history
update unstableResp3Module flag to only commands that have unstable api

add ability to tag commands to ignore user type mapping (as transformReply will convert it to a non typed map type)
	update bloom info commands to work with new non typed map ability

fill in search/time-series commands and tag with unstableResp3Modules flag as appropriate
  • Loading branch information
sjpotter committed Jun 2, 2024
1 parent 50fc454 commit 2b6e99a
Show file tree
Hide file tree
Showing 53 changed files with 1,070 additions and 568 deletions.
65 changes: 62 additions & 3 deletions packages/bloom/lib/commands/bloom/INFO.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisArgument, Command, UnwrapReply, NullReply, BlobStringReply, NumberReply, TuplesToMapReply, Resp2Reply } from '@redis/client/dist/lib/RESP/types';

export type BfInfoReplyMap = TuplesToMapReply<[
[BlobStringReply<'Capacity'>, NumberReply],
[BlobStringReply<'Size'>, NumberReply],
[BlobStringReply<'Number of filters'>, NumberReply],
[BlobStringReply<'Number of items inserted'>, NumberReply],
[BlobStringReply<'Expansion rate'>, NullReply | NumberReply]
]>;

export interface BfInfoReply {
capacity?: NumberReply;
size?: NumberReply;
numberOfFilters?: NumberReply;
numberOfInsertedItems?: NumberReply;
expansionRate?: NullReply | NumberReply;
}

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument) {
return ['BF.INFO', key];
},
// TODO
transformReply: undefined as unknown as () => any
transformReply: {
2: (reply: UnwrapReply<Resp2Reply<BfInfoReplyMap>>): BfInfoReply => {
return {
capacity: reply[1],
size: reply[3],
numberOfFilters: reply[5],
numberOfInsertedItems: reply[7],
expansionRate: reply[9]
}
},
3: (reply: UnwrapReply<BfInfoReplyMap>) => {
if (reply instanceof Map) {
throw new Error("BF.INFO shouldn't return a map type in resp3 anymore");
/*
return {
capacity: reply.get("Capacity" as unknown as BlobStringReply<'Capacity'>),
size: reply.get("Size" as unknown as BlobStringReply<"Size">),
numberOfFilters: reply.get("Number of filters" as unknown as BlobStringReply<"Number of filters">),
numberOfInsertedItems: reply.get('Number of items inserted' as unknown as BlobStringReply<'Number of items inserted'>),
expansionRate: reply.get('Expansion rate' as unknown as BlobStringReply<'Expansion rate'>),
}
*/
} else if (reply instanceof Array) {
throw new Error("BF.INFO shouldn't return a array type in resp3 anymore");
/*
return {
capacity: reply[1],
size: reply[3],
numberOfFilters: reply[5],
numberOfInsertedItems: reply[7],
expansionRate: reply[9]
}
*/
} else {
return {
capacity: reply["Capacity"],
size: reply["Size"],
numberOfFilters: reply["Number of filters"],
numberOfInsertedItems: reply["Number of items inserted"],
expansionRate: reply["Expansion rate"]
}
}
},
},
ignoreTypeMapping: true
} as const satisfies Command;
51 changes: 43 additions & 8 deletions packages/bloom/lib/commands/count-min-sketch/INFO.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { RedisArgument, TuplesToMapReply, BlobStringReply, NumberReply, UnwrapReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';

export type BfInfoReply = TuplesToMapReply<[
export type CmsInfoReplyMap = TuplesToMapReply<[
[BlobStringReply<'width'>, NumberReply],
[BlobStringReply<'depth'>, NumberReply],
[BlobStringReply<'count'>, NumberReply]
]>;

export interface CmsInfoReply {
width?: NumberReply;
depth?: NumberReply;
count?: NumberReply;
}

export default {
FIRST_KEY_INDEX: 1,
Expand All @@ -13,11 +19,40 @@ export default {
return ['CMS.INFO', key];
},
transformReply: {
2: (reply: UnwrapReply<Resp2Reply<BfInfoReply>>) => ({
width: reply[1],
depth: reply[3],
count: reply[5]
}),
3: undefined as unknown as () => BfInfoReply
}
2: (reply: UnwrapReply<Resp2Reply<CmsInfoReplyMap>>): CmsInfoReply => {
return {
width: reply[1],
depth: reply[3],
count: reply[5]
}
},
3: (reply: UnwrapReply<CmsInfoReplyMap>): CmsInfoReply => {
if (reply instanceof Map) {
throw new Error("BF.INFO shouldn't return a nap type in resp3 anymore");
/*
return {
width: reply.get("width" as unknown as BlobStringReply<'width'>),
depth: reply.get("depth" as unknown as BlobStringReply<"depth">),
count: reply.get("count" as unknown as BlobStringReply<"count">)
}
*/
} else if (reply instanceof Array) {
throw new Error("BF.INFO shouldn't return a array type in resp3 anymore");
/*
return {
width: reply[1],
depth: reply[3],
count: reply[5]
}
*/
} else {
return {
width: reply['width'],
depth: reply['depth'],
count: reply['count']
}
}
}
},
ignoreTypeMapping: true
} as const satisfies Command;
126 changes: 81 additions & 45 deletions packages/bloom/lib/commands/cuckoo/INFO.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,89 @@
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisArgument, Command, NumberReply, BlobStringReply, TuplesToMapReply, UnwrapReply, Resp2Reply } from '@redis/client/dist/lib/RESP/types';

export type CfInfoReplyMap = TuplesToMapReply<[
[BlobStringReply<'Size'>, NumberReply],
[BlobStringReply<'Number of buckets'>, NumberReply],
[BlobStringReply<'Number of filters'>, NumberReply],
[BlobStringReply<'Number of items inserted'>, NumberReply],
[BlobStringReply<'Number of items deleted'>, NumberReply],
[BlobStringReply<'Bucket size'>, NumberReply],
[BlobStringReply<'Expansion rate'>, NumberReply],
[BlobStringReply<'Max iterations'>, NumberReply]
]>;

export interface CfInfoReply {
size: NumberReply;
numberOfBuckets: NumberReply;
numberOfFilters: NumberReply;
numberOfInsertedItems: NumberReply;
numberOfDeletedItems: NumberReply;
bucketSize: NumberReply;
expansionRate: NumberReply;
maxIteration: NumberReply;
}

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument) {
return ['CF.INFO', key];
},
// TODO
// export type InfoRawReply = [
// _: string,
// size: number,
// _: string,
// numberOfBuckets: number,
// _: string,
// numberOfFilters: number,
// _: string,
// numberOfInsertedItems: number,
// _: string,
// numberOfDeletedItems: number,
// _: string,
// bucketSize: number,
// _: string,
// expansionRate: number,
// _: string,
// maxIteration: number
// ];

// export interface InfoReply {
// size: number;
// numberOfBuckets: number;
// numberOfFilters: number;
// numberOfInsertedItems: number;
// numberOfDeletedItems: number;
// bucketSize: number;
// expansionRate: number;
// maxIteration: number;
// }

// export function transformReply(reply: InfoRawReply): InfoReply {
// return {
// size: reply[1],
// numberOfBuckets: reply[3],
// numberOfFilters: reply[5],
// numberOfInsertedItems: reply[7],
// numberOfDeletedItems: reply[9],
// bucketSize: reply[11],
// expansionRate: reply[13],
// maxIteration: reply[15]
// };
// }
transformReply: undefined as unknown as () => any

transformReply: {
2: (reply: UnwrapReply<Resp2Reply<CfInfoReplyMap>>): CfInfoReply => {
return {
size: reply[1],
numberOfBuckets: reply[3],
numberOfFilters: reply[5],
numberOfInsertedItems: reply[7],
numberOfDeletedItems: reply[9],
bucketSize: reply[11],
expansionRate: reply[13],
maxIteration: reply[15]
}
},
3: (reply: UnwrapReply<CfInfoReplyMap>): CfInfoReply => {
if (reply instanceof Map) {
throw new Error("BF.INFO shouldn't return a map type in resp3 anymore");
/*
return {
size: reply.get("Size" as unknown as BlobStringReply<"Size">)!,
numberOfBuckets: reply.get('Number of buckets' as unknown as BlobStringReply<'Number of buckets'>)!,
numberOfFilters: reply.get('Number of filters' as unknown as BlobStringReply<"Number of filters">)!,
numberOfInsertedItems: reply.get('Number of items inserted' as unknown as BlobStringReply<'Number of items inserted'>)!,
numberOfDeletedItems: reply.get('Number of items deleted' as unknown as BlobStringReply<'Number of items deleted'>)!,
bucketSize: reply.get('Bucket size' as unknown as BlobStringReply<'Bucket size'>)!,
expansionRate: reply.get('Expansion rate' as unknown as BlobStringReply<'Expansion rate'>)!,
maxIteration: reply.get('Max iterations' as unknown as BlobStringReply<'Max iterations'>)!
}
*/
} else if (reply instanceof Array) {
throw new Error("BF.INFO shouldn't return a array type in resp3 anymore");
/*
return {
size: reply[1],
numberOfBuckets: reply[3],
numberOfFilters: reply[5],
numberOfInsertedItems: reply[7],
numberOfDeletedItems: reply[9],
bucketSize: reply[11],
expansionRate: reply[13],
maxIteration: reply[15]
}
*/
} else {
return {
size: reply['Size'],
numberOfBuckets: reply['Number of buckets'],
numberOfFilters: reply['Number of filters'],
numberOfInsertedItems: reply['Number of items inserted'],
numberOfDeletedItems: reply['Number of items deleted'],
bucketSize: reply['Bucket size'],
expansionRate: reply['Expansion rate'],
maxIteration: reply['Max iterations']
}
}
}
},
ignoreTypeMapping: true
} as const satisfies Command;
Loading

0 comments on commit 2b6e99a

Please sign in to comment.