-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module commands to be marked as unstable and require clients to opt in #2766
Changes from 12 commits
3892f92
54d2c0d
5806f68
0f2e8d5
f8a300f
1c77ab0
f13f47a
5daf11b
a91dded
9baec20
33adc6f
8e7f11c
465911e
f08e94f
6e60233
6c34d6b
d896b09
7327f5e
9a85b10
f555c4d
17e4dd5
629e790
418f79e
9dde283
4dea5cb
4f74a86
f0af1eb
4bee30f
77592d2
60499fc
2ac0964
aef901e
60fd22c
4066097
2b2bbb5
9ac2ee8
0337343
f3013f1
11bd5d2
142dfb4
d42fd70
78f1de6
5676a72
e57ca82
bf8a93c
52bd5c0
3d0485b
9adac9d
ea51f39
5202955
b4b67f6
58f88b5
8ad4171
d0396e7
faa67f3
830d5db
fcdb1c0
7ead8e4
68ca83b
9e8c183
3f65936
839e14b
91ed69e
2d18b36
31d61b8
25fdd32
59a27cc
bf11c35
1a5ac15
16950d0
e1b935c
1f346f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,69 @@ | ||
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types'; | ||
import { RedisArgument, Command, UnwrapReply, NullReply, NumberReply, TuplesToMapReply, Resp2Reply, SimpleStringReply } from '@redis/client/dist/lib/RESP/types'; | ||
|
||
export type BfInfoReplyMap = TuplesToMapReply<[ | ||
[SimpleStringReply<'Capacity'>, NumberReply], | ||
[SimpleStringReply<'Size'>, NumberReply], | ||
[SimpleStringReply<'Number of filters'>, NumberReply], | ||
[SimpleStringReply<'Number of items inserted'>, NumberReply], | ||
[SimpleStringReply<'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>): BfInfoReply => { | ||
if (reply instanceof Map) { | ||
throw new Error("BF.INFO shouldn't be used with type mapping to map or array"); | ||
/* | ||
return { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should only modify the keys ( edit: same for some more info commands, I'm not going to copy this comment.. |
||
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 be used with type mapping to map or array"); | ||
/* | ||
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"] | ||
} | ||
} | ||
}, | ||
}, | ||
} as const satisfies Command; |
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'; | ||
import { RedisArgument, TuplesToMapReply, NumberReply, UnwrapReply, Resp2Reply, Command, SimpleStringReply } from '@redis/client/dist/lib/RESP/types'; | ||
|
||
export type BfInfoReply = TuplesToMapReply<[ | ||
[BlobStringReply<'width'>, NumberReply], | ||
[BlobStringReply<'depth'>, NumberReply], | ||
[BlobStringReply<'count'>, NumberReply] | ||
export type CmsInfoReplyMap = TuplesToMapReply<[ | ||
[SimpleStringReply<'width'>, NumberReply], | ||
[SimpleStringReply<'depth'>, NumberReply], | ||
[SimpleStringReply<'count'>, NumberReply] | ||
]>; | ||
|
||
export interface CmsInfoReply { | ||
width?: NumberReply; | ||
depth?: NumberReply; | ||
count?: NumberReply; | ||
} | ||
|
||
export default { | ||
FIRST_KEY_INDEX: 1, | ||
|
@@ -13,11 +19,39 @@ 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in this case we should just return the reply as is, as we don't modify the keys nor the values edit: same for some more info commands, I'm not going to copy this comment.. |
||
throw new Error("CMS.INFO shouldn't be used with type mapping to map or array"); | ||
/* | ||
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("CMS.INFO shouldn't be used with type mapping to map or array"); | ||
/* | ||
return { | ||
width: reply[1], | ||
depth: reply[3], | ||
count: reply[5] | ||
} | ||
*/ | ||
} else { | ||
return { | ||
width: reply['width'], | ||
depth: reply['depth'], | ||
count: reply['count'] | ||
} | ||
} | ||
} | ||
}, | ||
} as const satisfies Command; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,88 @@ | ||
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types'; | ||
import { RedisArgument, Command, NumberReply, TuplesToMapReply, UnwrapReply, Resp2Reply, SimpleStringReply } from '@redis/client/dist/lib/RESP/types'; | ||
|
||
export type CfInfoReplyMap = TuplesToMapReply<[ | ||
[SimpleStringReply<'Size'>, NumberReply], | ||
[SimpleStringReply<'Number of buckets'>, NumberReply], | ||
[SimpleStringReply<'Number of filters'>, NumberReply], | ||
[SimpleStringReply<'Number of items inserted'>, NumberReply], | ||
[SimpleStringReply<'Number of items deleted'>, NumberReply], | ||
[SimpleStringReply<'Bucket size'>, NumberReply], | ||
[SimpleStringReply<'Expansion rate'>, NumberReply], | ||
[SimpleStringReply<'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("CF.INFO shouldn't be used with type mapping to map or array"); | ||
/* | ||
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("CF.INFO shouldn't be used with type mapping to map or array"); | ||
/* | ||
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'] | ||
} | ||
} | ||
} | ||
}, | ||
} as const satisfies Command; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/redis/node-redis/blob/v5/docs/v4-to-v5.md?plain=1#L238
#2506
I'm not sure if we should keep the keys as is for the sake of consistency or transform them for the sake of "friendly/javascripty"..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it says there "to avoid unneccessary transformations" (and confusion but I honestly don't think that is the case).
In this case a transformation is neccessary anyways, so might as well make it friendly. I also distinguish between "info" objects that are defined data structures, and generic maps that can contain any set of keys/values (as I'll discuss on the next one)