-
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
add support for all hash field expiration commands #2742
Open
sjpotter
wants to merge
7
commits into
redis:v5
Choose a base branch
from
sjpotter:hash-expire
base: v5
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9bae18c
add support for all hash field expiration commands
sjpotter 0a87234
Update HEXPIRE.spec.ts
leibale 69be96f
Update HEXPIRE.ts
leibale 5ceb5f5
some cleanups
leibale 6a2c58b
some api changes
leibale 986bd84
add enum for HPERSIST reply
sjpotter 9252bf2
add enum for "error" codes for HPEXPIRETIME, but unsure how to expose…
sjpotter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { strict as assert } from 'node:assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import HEXPIRE from './HEXPIRE'; | ||
|
||
describe('HEXPIRE', () => { | ||
testUtils.isVersionGreaterThanHook([7, 4]); | ||
|
||
describe('transformArguments', () => { | ||
it('string', () => { | ||
assert.deepEqual( | ||
HEXPIRE.transformArguments('key', 'field', 1), | ||
['HEXPIRE', 'key', '1', '1', 'field'] | ||
); | ||
}); | ||
|
||
it('array', () => { | ||
assert.deepEqual( | ||
HEXPIRE.transformArguments('key', ['field1', 'field2'], 1), | ||
['HEXPIRE', 'key', '1', '2', 'field1', 'field2'] | ||
); | ||
}); | ||
|
||
it('with set option', () => { | ||
assert.deepEqual( | ||
HEXPIRE.transformArguments('key', 'field1', 1, 'NX'), | ||
['HEXPIRE', 'key', '1', 'NX', '1', 'field1'] | ||
); | ||
}); | ||
}); | ||
|
||
testUtils.testAll('hExpire', async client => { | ||
assert.equal( | ||
await client.hExpire('key', ['field1'], 0), | ||
null | ||
); | ||
}, { | ||
client: GLOBAL.SERVERS.OPEN, | ||
cluster: GLOBAL.CLUSTERS.OPEN | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Command, NullReply, RedisArgument } from "../RESP/types"; | ||
import { RedisVariadicArgument, pushVariadicArgument } from "./generic-transformers"; | ||
|
||
export const HASH_EXPIRATION = { | ||
/** The field does not exist */ | ||
FIELD_NOT_EXISTS: -2, | ||
/** Specified NX | XX | GT | LT condition not met */ | ||
CONDITION_NOT_MET: 0, | ||
/** Expiration time was set or updated */ | ||
UPDATED: 1, | ||
/** Field deleted because the specified expiration time is in the past */ | ||
DELETED: 2 | ||
} as const; | ||
|
||
export type HashExpiration = typeof HASH_EXPIRATION[keyof typeof HASH_EXPIRATION]; | ||
|
||
export default { | ||
FIRST_KEY_INDEX: 1, | ||
transformArguments( | ||
key: RedisArgument, | ||
fields: RedisVariadicArgument, | ||
seconds: number, | ||
mode?: 'NX' | 'XX' | 'GT' | 'LT', | ||
) { | ||
const args = ['HEXPIRE', key, seconds.toString()]; | ||
|
||
if (mode) { | ||
args.push(mode); | ||
} | ||
|
||
return pushVariadicArgument(args, fields); | ||
}, | ||
transformReply: undefined as unknown as () => NullReply | Array<HashExpiration> | ||
} as const satisfies Command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { strict as assert } from 'node:assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import HEXPIREAT from './HEXPIREAT'; | ||
|
||
describe('HEXPIREAT', () => { | ||
testUtils.isVersionGreaterThanHook([7, 4]); | ||
|
||
describe('transformArguments', () => { | ||
it('string + number', () => { | ||
assert.deepEqual( | ||
HEXPIREAT.transformArguments('key', 'field', 1), | ||
['HEXPIREAT', 'key', '1', '1', 'field'] | ||
); | ||
}); | ||
|
||
it('array + number', () => { | ||
assert.deepEqual( | ||
HEXPIREAT.transformArguments('key', ['field1', 'field2'], 1), | ||
['HEXPIREAT', 'key', '1', '2', 'field1', 'field2'] | ||
); | ||
}); | ||
|
||
it('date', () => { | ||
const d = new Date(); | ||
assert.deepEqual( | ||
HEXPIREAT.transformArguments('key', ['field1'], d), | ||
['HEXPIREAT', 'key', Math.floor(d.getTime() / 1000).toString(), '1', 'field1'] | ||
); | ||
}); | ||
|
||
it('with set option', () => { | ||
assert.deepEqual( | ||
HEXPIREAT.transformArguments('key', 'field1', 1, 'GT'), | ||
['HEXPIREAT', 'key', '1', 'GT', 1, 'field1'] | ||
); | ||
}); | ||
}); | ||
|
||
testUtils.testAll('expireAt', async client => { | ||
assert.equal( | ||
await client.hExpireAt('key', 'field1', 1), | ||
null | ||
); | ||
}, { | ||
client: GLOBAL.SERVERS.OPEN, | ||
cluster: GLOBAL.CLUSTERS.OPEN | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { RedisArgument, Command, NullReply } from '../RESP/types'; | ||
import { HashExpiration } from './HEXPIRE'; | ||
import { RedisVariadicArgument, pushVariadicArgument, transformEXAT } from './generic-transformers'; | ||
|
||
export default { | ||
FIRST_KEY_INDEX: 1, | ||
IS_READ_ONLY: true, | ||
transformArguments( | ||
key: RedisArgument, | ||
fields: RedisVariadicArgument, | ||
timestamp: number | Date, | ||
mode?: 'NX' | 'XX' | 'GT' | 'LT' | ||
) { | ||
const args = ['HEXPIREAT', key, transformEXAT(timestamp)]; | ||
|
||
if (mode) { | ||
args.push(mode); | ||
} | ||
|
||
return pushVariadicArgument(args, fields); | ||
}, | ||
transformReply: undefined as unknown as () => NullReply | Array<HashExpiration> | ||
} as const satisfies Command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { strict as assert } from 'node:assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import HEXPIRETIME from './HEXPIRETIME'; | ||
|
||
describe('HEXPIRETIME', () => { | ||
testUtils.isVersionGreaterThanHook([7, 4]); | ||
|
||
describe('transformArguments', () => { | ||
it('string', () => { | ||
assert.deepEqual( | ||
HEXPIRETIME.transformArguments('key', 'field'), | ||
['HEXPIRETIME', 'key', '1', 'field'] | ||
); | ||
}); | ||
|
||
it('array', () => { | ||
assert.deepEqual( | ||
HEXPIRETIME.transformArguments('key', ['field1', 'field2']), | ||
['HEXPIRETIME', 'key', '2', 'field1', 'field2'] | ||
); | ||
}); | ||
}) | ||
|
||
testUtils.testAll('hExpireTime', async client => { | ||
assert.equal( | ||
await client.hExpireTime('key', 'field'), | ||
null | ||
); | ||
}, { | ||
client: GLOBAL.SERVERS.OPEN, | ||
cluster: GLOBAL.CLUSTERS.OPEN | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { RedisArgument, NumberReply, Command, NullReply, ArrayReply } from '../RESP/types'; | ||
import { RedisVariadicArgument, pushVariadicArgument } from './generic-transformers'; | ||
|
||
export default { | ||
FIRST_KEY_INDEX: 1, | ||
IS_READ_ONLY: true, | ||
transformArguments(key: RedisArgument, fields: RedisVariadicArgument) { | ||
return pushVariadicArgument(['HEXPIRETIME', key], fields); | ||
}, | ||
transformReply: undefined as unknown as () => NullReply | ArrayReply<NumberReply> | ||
leibale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} as const satisfies Command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { strict as assert } from 'node:assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import HPERSIST from './HPERSIST'; | ||
|
||
describe('HPERSIST', () => { | ||
testUtils.isVersionGreaterThanHook([7, 4]); | ||
|
||
describe('transformArguments', () => { | ||
it('string', () => { | ||
assert.deepEqual( | ||
HPERSIST.transformArguments('key', 'field'), | ||
['HPERSIST', 'key', '1', 'field'] | ||
); | ||
}); | ||
|
||
it('array', () => { | ||
assert.deepEqual( | ||
HPERSIST.transformArguments('key', ['field1', 'field2']), | ||
['HPERSIST', 'key', '2', 'field1', 'field2'] | ||
); | ||
}); | ||
}) | ||
|
||
testUtils.testAll('hPersist', async client => { | ||
assert.equal( | ||
await client.hPersist('key', 'field1'), | ||
null | ||
); | ||
}, { | ||
client: GLOBAL.SERVERS.OPEN, | ||
cluster: GLOBAL.CLUSTERS.OPEN | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { RedisArgument, NumberReply, Command, NullReply, ArrayReply } from '../RESP/types'; | ||
import { RedisVariadicArgument, pushVariadicArgument } from './generic-transformers'; | ||
|
||
export default { | ||
FIRST_KEY_INDEX: 1, | ||
transformArguments(key: RedisArgument, fields: RedisVariadicArgument) { | ||
return pushVariadicArgument(['HPERSIST', key], fields); | ||
}, | ||
transformReply: undefined as unknown as () => NullReply | ArrayReply<NumberReply> | ||
} as const satisfies Command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { strict as assert } from 'node:assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import HPEXPIRE from './HPEXPIRE'; | ||
|
||
describe('HPEXPIRE', () => { | ||
testUtils.isVersionGreaterThanHook([7, 4]); | ||
|
||
describe('transformArguments', () => { | ||
it('string', () => { | ||
assert.deepEqual( | ||
HPEXPIRE.transformArguments('key', 'field', 1), | ||
['HPEXPIRE', 'key', '1', '1', 'field'] | ||
); | ||
}); | ||
|
||
it('array', () => { | ||
assert.deepEqual( | ||
HPEXPIRE.transformArguments('key', ['field1', 'field2'], 1), | ||
['HPEXPIRE', 'key', '1', '2', 'field1', 'field2'] | ||
); | ||
}); | ||
|
||
it('with set option', () => { | ||
assert.deepEqual( | ||
HPEXPIRE.transformArguments('key', ['field1'], 1, 'NX'), | ||
['HPEXPIRE', 'key', '1', 'NX', '1', 'field1'] | ||
); | ||
}); | ||
}); | ||
|
||
testUtils.testAll('hpRxpire', async client => { | ||
assert.equal( | ||
await client.hpExpire('key', ['field'], 0), | ||
null | ||
); | ||
}, { | ||
client: GLOBAL.SERVERS.OPEN, | ||
cluster: GLOBAL.CLUSTERS.OPEN | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Command, NullReply, RedisArgument } from "../RESP/types"; | ||
import { HashExpiration } from "./HEXPIRE"; | ||
import { RedisVariadicArgument, pushVariadicArgument } from "./generic-transformers"; | ||
|
||
export default { | ||
FIRST_KEY_INDEX: 1, | ||
transformArguments( | ||
key: RedisArgument, | ||
fields: RedisVariadicArgument, | ||
ms: number, | ||
mode?: 'NX' | 'XX' | 'GT' | 'LT', | ||
) { | ||
const args = ['HPEXPIRE', key, ms.toString()]; | ||
|
||
if (mode) { | ||
args.push(mode); | ||
} | ||
|
||
return pushVariadicArgument(args, fields); | ||
}, | ||
transformReply: undefined as unknown as () => NullReply | Array<HashExpiration> | ||
} as const satisfies Command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { strict as assert } from 'node:assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import HPEXPIREAT from './HPEXPIREAT'; | ||
|
||
describe('HPEXPIREAT', () => { | ||
testUtils.isVersionGreaterThanHook([7, 4]); | ||
|
||
describe('transformArguments', () => { | ||
it('string + number', () => { | ||
assert.deepEqual( | ||
HPEXPIREAT.transformArguments('key', 'field', 1), | ||
['HPEXPIREAT', 'key', '1', '1', 'field'] | ||
); | ||
}); | ||
|
||
it('array + number', () => { | ||
assert.deepEqual( | ||
HPEXPIREAT.transformArguments('key', ['field1', 'field2'], 1), | ||
['HPEXPIREAT', 'key', '1', '2', 'field1', 'field2'] | ||
); | ||
}); | ||
|
||
it('date', () => { | ||
const d = new Date(); | ||
assert.deepEqual( | ||
HPEXPIREAT.transformArguments('key', ['field1'], d), | ||
['HPEXPIREAT', 'key', d.getTime().toString(), '1', 'field1'] | ||
); | ||
}); | ||
|
||
it('with set option', () => { | ||
assert.deepEqual( | ||
HPEXPIREAT.transformArguments('key', ['field1'], 1, 'XX'), | ||
['HPEXPIREAT', 'key', '1', 'XX', '1', 'field1'] | ||
); | ||
}); | ||
}); | ||
|
||
testUtils.testAll('hpExpireAt', async client => { | ||
assert.equal( | ||
await client.hpExpireAt('key', ['field1'], 1), | ||
null, | ||
); | ||
}, { | ||
client: GLOBAL.SERVERS.OPEN, | ||
cluster: GLOBAL.CLUSTERS.OPEN | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { RedisArgument, Command, NullReply } from '../RESP/types'; | ||
import { HashExpiration } from './HEXPIRE'; | ||
import { RedisVariadicArgument, pushVariadicArgument, transformEXAT } from './generic-transformers'; | ||
|
||
export default { | ||
FIRST_KEY_INDEX: 1, | ||
IS_READ_ONLY: true, | ||
transformArguments( | ||
key: RedisArgument, | ||
fields: RedisVariadicArgument, | ||
timestamp: number | Date, | ||
mode?: 'NX' | 'XX' | 'GT' | 'LT' | ||
) { | ||
const args = ['HPEXPIREAT', key, transformEXAT(timestamp)]; | ||
|
||
if (mode) { | ||
args.push(mode); | ||
} | ||
|
||
return pushVariadicArgument(args, fields); | ||
}, | ||
transformReply: undefined as unknown as () => NullReply | Array<HashExpiration> | ||
} as const satisfies Command; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we do
for "future proofing" (in case there will be more optional arguments)
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 doesn't really future proof, it just makes it easier if these options are shared between multiple commands. Unsure it adds that much.