-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the NOVALUES option of HSCAN (#2711)
* Support the NOVALUES option of HSCAN Issue #2705 The NOVALUES option instructs HSCAN to only return keys, without their values. This is materialized as a new command, `hScanNoValues`, given that the return type is different from the usual return type of `hScan`. Also a new iterator is provided, `hScanNoValuesIterator`, for the same reason. * skip hscan novalues test if redis < 7.4 * Also don't test hscan no values iterator < 7.4 --------- Co-authored-by: Shaya Potter <spotter@gmail.com>
- Loading branch information
Showing
7 changed files
with
160 additions
and
2 deletions.
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
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
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
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
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
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,79 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments, transformReply } from './HSCAN_NOVALUES'; | ||
|
||
describe('HSCAN_NOVALUES', () => { | ||
testUtils.isVersionGreaterThanHook([7, 4]); | ||
|
||
describe('transformArguments', () => { | ||
it('cusror only', () => { | ||
assert.deepEqual( | ||
transformArguments('key', 0), | ||
['HSCAN', 'key', '0', 'NOVALUES'] | ||
); | ||
}); | ||
|
||
it('with MATCH', () => { | ||
assert.deepEqual( | ||
transformArguments('key', 0, { | ||
MATCH: 'pattern' | ||
}), | ||
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'NOVALUES'] | ||
); | ||
}); | ||
|
||
it('with COUNT', () => { | ||
assert.deepEqual( | ||
transformArguments('key', 0, { | ||
COUNT: 1 | ||
}), | ||
['HSCAN', 'key', '0', 'COUNT', '1', 'NOVALUES'] | ||
); | ||
}); | ||
}); | ||
|
||
describe('transformReply', () => { | ||
it('without keys', () => { | ||
assert.deepEqual( | ||
transformReply(['0', []]), | ||
{ | ||
cursor: 0, | ||
keys: [] | ||
} | ||
); | ||
}); | ||
|
||
it('with keys', () => { | ||
assert.deepEqual( | ||
transformReply(['0', ['key1', 'key2']]), | ||
{ | ||
cursor: 0, | ||
keys: ['key1', 'key2'] | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
testUtils.testWithClient('client.hScanNoValues', async client => { | ||
assert.deepEqual( | ||
await client.hScanNoValues('key', 0), | ||
{ | ||
cursor: 0, | ||
keys: [] | ||
} | ||
); | ||
|
||
await Promise.all([ | ||
client.hSet('key', 'a', '1'), | ||
client.hSet('key', 'b', '2') | ||
]); | ||
|
||
assert.deepEqual( | ||
await client.hScanNoValues('key', 0), | ||
{ | ||
cursor: 0, | ||
keys: ['a', 'b'] | ||
} | ||
); | ||
}, GLOBAL.SERVERS.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,27 @@ | ||
import { RedisCommandArgument, RedisCommandArguments } from '.'; | ||
import { ScanOptions } from './generic-transformers'; | ||
import { HScanRawReply, transformArguments as transformHScanArguments } from './HSCAN'; | ||
|
||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './HSCAN'; | ||
|
||
export function transformArguments( | ||
key: RedisCommandArgument, | ||
cursor: number, | ||
options?: ScanOptions | ||
): RedisCommandArguments { | ||
const args = transformHScanArguments(key, cursor, options); | ||
args.push('NOVALUES'); | ||
return args; | ||
} | ||
|
||
interface HScanNoValuesReply { | ||
cursor: number; | ||
keys: Array<RedisCommandArgument>; | ||
} | ||
|
||
export function transformReply([cursor, rawData]: HScanRawReply): HScanNoValuesReply { | ||
return { | ||
cursor: Number(cursor), | ||
keys: [...rawData] | ||
}; | ||
} |