-
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.
- Loading branch information
Showing
21 changed files
with
379 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../../test-utils'; | ||
import { transformArguments } from './LIST_WITHCOUNT'; | ||
|
||
describe('TOPK LIST WITHCOUNT', () => { | ||
testUtils.isVersionGreaterThanHook([2, 2, 9]); | ||
|
||
it('transformArguments', () => { | ||
assert.deepEqual( | ||
transformArguments('key'), | ||
['TOPK.LIST', 'key', 'WITHCOUNT'] | ||
); | ||
}); | ||
|
||
testUtils.testWithClient('client.topK.listWithCount', async client => { | ||
const [,, list] = await Promise.all([ | ||
client.topK.reserve('key', 3), | ||
client.topK.add('key', 'item'), | ||
client.topK.listWithCount('key') | ||
]); | ||
|
||
assert.deepEqual( | ||
list, | ||
[{ | ||
item: 'item', | ||
count: 1 | ||
}] | ||
); | ||
}, 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,26 @@ | ||
export const FIRST_KEY_INDEX = 1; | ||
|
||
export const IS_READ_ONLY = true; | ||
|
||
export function transformArguments(key: string): Array<string> { | ||
return ['TOPK.LIST', key, 'WITHCOUNT']; | ||
} | ||
|
||
type ListWithCountRawReply = Array<string | number>; | ||
|
||
type ListWithCountReply = Array<{ | ||
item: string, | ||
count: number | ||
}>; | ||
|
||
export function transformReply(rawReply: ListWithCountRawReply): ListWithCountReply { | ||
const reply: ListWithCountReply = []; | ||
for (let i = 0; i < rawReply.length; i++) { | ||
reply.push({ | ||
item: rawReply[i] as string, | ||
count: rawReply[++i] as number | ||
}); | ||
} | ||
|
||
return reply; | ||
} |
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,32 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './BLMPOP'; | ||
|
||
describe('BLMPOP', () => { | ||
testUtils.isVersionGreaterThanHook([7, 0]); | ||
|
||
describe('transformArguments', () => { | ||
it('simple', () => { | ||
assert.deepEqual( | ||
transformArguments(0, 'key', 'LEFT'), | ||
['BLMPOP', '0', '1', 'key', 'LEFT'] | ||
); | ||
}); | ||
|
||
it('with COUNT', () => { | ||
assert.deepEqual( | ||
transformArguments(0, 'key', 'LEFT', { | ||
COUNT: 2 | ||
}), | ||
['BLMPOP', '0', '1', 'key', 'LEFT', 'COUNT', '2'] | ||
); | ||
}); | ||
}); | ||
|
||
testUtils.testWithClient('client.blmPop', async client => { | ||
assert.deepEqual( | ||
await client.blmPop(1, 'key', 'RIGHT'), | ||
null | ||
); | ||
}, 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,20 @@ | ||
import { RedisCommandArgument, RedisCommandArguments } from '.'; | ||
import { transformLMPopArguments, LMPopOptions, ListSide } from './generic-transformers'; | ||
|
||
export const FIRST_KEY_INDEX = 3; | ||
|
||
export function transformArguments( | ||
timeout: number, | ||
keys: RedisCommandArgument | Array<RedisCommandArgument>, | ||
side: ListSide, | ||
options?: LMPopOptions | ||
): RedisCommandArguments { | ||
return transformLMPopArguments( | ||
['BLMPOP', timeout.toString()], | ||
keys, | ||
side, | ||
options | ||
); | ||
} | ||
|
||
export { transformReply } from './LMPOP'; |
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,32 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './BZMPOP'; | ||
|
||
describe('BZMPOP', () => { | ||
testUtils.isVersionGreaterThanHook([7, 0]); | ||
|
||
describe('transformArguments', () => { | ||
it('simple', () => { | ||
assert.deepEqual( | ||
transformArguments(0, 'key', 'MIN'), | ||
['BZMPOP', '0', '1', 'key', 'MIN'] | ||
); | ||
}); | ||
|
||
it('with COUNT', () => { | ||
assert.deepEqual( | ||
transformArguments(0, 'key', 'MIN', { | ||
COUNT: 2 | ||
}), | ||
['BZMPOP', '0', '1', 'key', 'MIN', 'COUNT', '2'] | ||
); | ||
}); | ||
}); | ||
|
||
testUtils.testWithClient('client.bzmPop', async client => { | ||
assert.deepEqual( | ||
await client.bzmPop(1, 'key', 'MAX'), | ||
null | ||
); | ||
}, 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,20 @@ | ||
import { RedisCommandArgument, RedisCommandArguments } from '.'; | ||
import { SortedSetSide, transformZMPopArguments, ZMPopOptions } from './generic-transformers'; | ||
|
||
export const FIRST_KEY_INDEX = 3; | ||
|
||
export function transformArguments( | ||
timeout: number, | ||
keys: RedisCommandArgument | Array<RedisCommandArgument>, | ||
side: SortedSetSide, | ||
options?: ZMPopOptions | ||
): RedisCommandArguments { | ||
return transformZMPopArguments( | ||
['BZMPOP', timeout.toString()], | ||
keys, | ||
side, | ||
options | ||
); | ||
} | ||
|
||
export { transformReply } from './ZMPOP'; |
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,32 @@ | ||
import { strict as assert } from 'assert'; | ||
import testUtils, { GLOBAL } from '../test-utils'; | ||
import { transformArguments } from './LMPOP'; | ||
|
||
describe('LMPOP', () => { | ||
testUtils.isVersionGreaterThanHook([7, 0]); | ||
|
||
describe('transformArguments', () => { | ||
it('simple', () => { | ||
assert.deepEqual( | ||
transformArguments('key', 'LEFT'), | ||
['LMPOP', '1', 'key', 'LEFT'] | ||
); | ||
}); | ||
|
||
it('with COUNT', () => { | ||
assert.deepEqual( | ||
transformArguments('key', 'LEFT', { | ||
COUNT: 2 | ||
}), | ||
['LMPOP', '1', 'key', 'LEFT', 'COUNT', '2'] | ||
); | ||
}); | ||
}); | ||
|
||
testUtils.testWithClient('client.lmPop', async client => { | ||
assert.deepEqual( | ||
await client.lmPop('key', 'RIGHT'), | ||
null | ||
); | ||
}, GLOBAL.SERVERS.OPEN); | ||
}); |
Oops, something went wrong.