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 11export const FIRST_KEY_INDEX = 1 ;
22
3+ export const IS_READ_ONLY = true ;
4+
35export function transformArguments ( key : string ) : Array < string > {
46 return [ 'TOPK.LIST' , key ] ;
57}
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 11export const FIRST_KEY_INDEX = 1 ;
22
3+ export const IS_READ_ONLY = true ;
4+
35interface ReserveOptions {
46 width : number ;
57 depth : number ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as ADD from './ADD';
22import * as COUNT from './COUNT' ;
33import * as INCRBY from './INCRBY' ;
44import * as INFO from './INFO' ;
5+ import * as LIST_WITHCOUNT from './LIST_WITHCOUNT' ;
56import * as LIST from './LIST' ;
67import * as QUERY from './QUERY' ;
78import * as RESERVE from './RESERVE' ;
@@ -15,6 +16,8 @@ export default {
1516 incrBy : INCRBY ,
1617 INFO ,
1718 info : INFO ,
19+ LIST_WITHCOUNT ,
20+ listWithCount : LIST_WITHCOUNT ,
1821 LIST ,
1922 list : LIST ,
2023 QUERY ,
You can’t perform that action at this time.
0 commit comments