File tree Expand file tree Collapse file tree 5 files changed +63
-0
lines changed
packages/bloom/lib/commands/top-k Expand file tree Collapse file tree 5 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 1
1
export const FIRST_KEY_INDEX = 1 ;
2
2
3
+ export const IS_READ_ONLY = true ;
4
+
3
5
export function transformArguments ( key : string ) : Array < string > {
4
6
return [ 'TOPK.LIST' , key ] ;
5
7
}
Original file line number Diff line number Diff line change
1
+ import { strict as assert } from 'assert' ;
2
+ import testUtils , { GLOBAL } from '../../test-utils' ;
3
+ import { transformArguments } from './LIST_WITHCOUNT' ;
4
+
5
+ describe ( 'TOPK LIST WITHCOUNT' , ( ) => {
6
+ testUtils . isVersionGreaterThanHook ( [ 2 , 2 , 9 ] ) ;
7
+
8
+ it ( 'transformArguments' , ( ) => {
9
+ assert . deepEqual (
10
+ transformArguments ( 'key' ) ,
11
+ [ 'TOPK.LIST' , 'key' , 'WITHCOUNT' ]
12
+ ) ;
13
+ } ) ;
14
+
15
+ testUtils . testWithClient ( 'client.topK.listWithCount' , async client => {
16
+ const [ , , list ] = await Promise . all ( [
17
+ client . topK . reserve ( 'key' , 3 ) ,
18
+ client . topK . add ( 'key' , 'item' ) ,
19
+ client . topK . listWithCount ( 'key' )
20
+ ] ) ;
21
+
22
+ assert . deepEqual (
23
+ list ,
24
+ [ {
25
+ item : 'item' ,
26
+ count : 1
27
+ } ]
28
+ ) ;
29
+ } , GLOBAL . SERVERS . OPEN ) ;
30
+ } ) ;
Original file line number Diff line number Diff line change
1
+ export const FIRST_KEY_INDEX = 1 ;
2
+
3
+ export const IS_READ_ONLY = true ;
4
+
5
+ export function transformArguments ( key : string ) : Array < string > {
6
+ return [ 'TOPK.LIST' , key , 'WITHCOUNT' ] ;
7
+ }
8
+
9
+ type ListWithCountRawReply = Array < string | number > ;
10
+
11
+ type ListWithCountReply = Array < {
12
+ item : string ,
13
+ count : number
14
+ } > ;
15
+
16
+ export function transformReply ( rawReply : ListWithCountRawReply ) : ListWithCountReply {
17
+ const reply : ListWithCountReply = [ ] ;
18
+ for ( let i = 0 ; i < rawReply . length ; i ++ ) {
19
+ reply . push ( {
20
+ item : rawReply [ i ] as string ,
21
+ count : rawReply [ ++ i ] as number
22
+ } ) ;
23
+ }
24
+
25
+ return reply ;
26
+ }
Original file line number Diff line number Diff line change 1
1
export const FIRST_KEY_INDEX = 1 ;
2
2
3
+ export const IS_READ_ONLY = true ;
4
+
3
5
interface ReserveOptions {
4
6
width : number ;
5
7
depth : number ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as ADD from './ADD';
2
2
import * as COUNT from './COUNT' ;
3
3
import * as INCRBY from './INCRBY' ;
4
4
import * as INFO from './INFO' ;
5
+ import * as LIST_WITHCOUNT from './LIST_WITHCOUNT' ;
5
6
import * as LIST from './LIST' ;
6
7
import * as QUERY from './QUERY' ;
7
8
import * as RESERVE from './RESERVE' ;
@@ -15,6 +16,8 @@ export default {
15
16
incrBy : INCRBY ,
16
17
INFO ,
17
18
info : INFO ,
19
+ LIST_WITHCOUNT ,
20
+ listWithCount : LIST_WITHCOUNT ,
18
21
LIST ,
19
22
list : LIST ,
20
23
QUERY ,
You can’t perform that action at this time.
0 commit comments