-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(client): require approximate modifier for XTRIM LIMIT #3425
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -3,20 +3,34 @@ import { NumberReply, Command, RedisArgument } from '../RESP/types'; | |
| import { StreamDeletionPolicy } from './common-stream.types'; | ||
|
|
||
| /** | ||
| * Options for the XTRIM command | ||
| * | ||
| * @property strategyModifier - Exact ('=') or approximate ('~') trimming | ||
| * Options for exact XTRIM trimming | ||
| * | ||
| * @property strategyModifier - Exact ('=') trimming | ||
| * @property policy - Policy to apply when deleting entries (optional, defaults to KEEPREF) | ||
| */ | ||
| export interface XTrimExactOptions { | ||
| strategyModifier?: '='; | ||
| /** added in 8.2 */ | ||
| policy?: StreamDeletionPolicy; | ||
|
Comment on lines
+11
to
+14
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.
Because Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| /** | ||
| * Options for approximate XTRIM trimming | ||
| * | ||
| * @property strategyModifier - Approximate ('~') trimming, required for LIMIT | ||
| * @property LIMIT - Maximum number of entries to trim in one call (Redis 6.2+) | ||
| * @property policy - Policy to apply when deleting entries (optional, defaults to KEEPREF) | ||
| */ | ||
| export interface XTrimOptions { | ||
| strategyModifier?: '=' | '~'; | ||
| export interface XTrimApproximateOptions { | ||
| strategyModifier: '~'; | ||
| /** added in 6.2 */ | ||
| LIMIT?: number; | ||
| /** added in 8.2 */ | ||
| policy?: StreamDeletionPolicy; | ||
| } | ||
|
|
||
| export type XTrimOptions = XTrimExactOptions | XTrimApproximateOptions; | ||
|
|
||
| /** | ||
| * Command for trimming a stream to a specified length or minimum ID | ||
| */ | ||
|
|
@@ -32,13 +46,13 @@ export default { | |
| parser.pushKey(key); | ||
| parser.push(strategy); | ||
|
|
||
| if (options?.strategyModifier) { | ||
| if (options?.strategyModifier !== undefined) { | ||
| parser.push(options.strategyModifier); | ||
| } | ||
|
|
||
| parser.push(threshold.toString()); | ||
|
|
||
| if (options?.LIMIT !== undefined) { | ||
| if (options?.strategyModifier === '~' && options.LIMIT !== undefined) { | ||
| parser.push('LIMIT', options.LIMIT.toString()); | ||
|
Comment on lines
+55
to
56
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.
When an invalid options object reaches this runtime path—such as from JavaScript, Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Compile-time regression: XTRIM's LIMIT is only accepted by the server | ||
| * together with the approximate modifier ("syntax error, LIMIT cannot be used | ||
| * without the special ~ option", t_stream.c), so the options type must not | ||
| * allow LIMIT without strategyModifier '~'. | ||
| * | ||
| * Lives outside `lib/` so it is not picked up by the production build / | ||
| * typedoc. Checked with `npm run test:types -w @redis/client`. | ||
| */ | ||
| import { XTrimOptions } from '../lib/commands/XTRIM'; | ||
|
|
||
| export function xtrimLimitRequiresApproximateModifier(): void { | ||
| // LIMIT without '~' is rejected by the server. | ||
| // @ts-expect-error LIMIT requires strategyModifier '~' | ||
| const invalid: XTrimOptions = { LIMIT: 10 }; | ||
|
|
||
| const valid: XTrimOptions = { strategyModifier: '~', LIMIT: 10 }; | ||
|
|
||
| console.log(invalid, valid); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.