File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -106,9 +106,8 @@ class buildRedisStoreWithConfig implements RedisStore {
106
106
return await this . redisCache . ttl ( key ) ;
107
107
} ;
108
108
109
- public async scan ( pattern : string ) : Promise < ScanReply > {
110
- let cursor = 0 ;
111
- return await this . redisCache . scan ( cursor , { MATCH : pattern } ) ;
109
+ public async scan ( pattern : string , cursor : number = 0 , count : number = 10 ) : Promise < ScanReply > {
110
+ return await this . redisCache . scan ( cursor , { MATCH : pattern , COUNT : count } ) ;
112
111
}
113
112
114
113
public getClient ( ) : RedisClientType < RedisDefaultModules & RedisModules , RedisFunctions , RedisScripts > {
Original file line number Diff line number Diff line change @@ -7,5 +7,5 @@ export interface RedisStore extends Store {
7
7
8
8
getClient ( ) : RedisClientType < RedisDefaultModules & RedisModules , RedisFunctions , RedisScripts > ;
9
9
10
- scan ( pattern : string ) : Promise < ScanReply > ;
10
+ scan ( pattern : string , cursor ? : number , count ?: number ) : Promise < ScanReply > ;
11
11
}
Original file line number Diff line number Diff line change @@ -93,5 +93,18 @@ describe('Redis Store', () => {
93
93
94
94
const res = await redisClient . scan ( 'ttl:a:*' ) ;
95
95
expect ( res . keys ) . toEqual ( [ key1 , key3 ] ) ;
96
+
97
+ const firstScanWithCount = await redisClient . scan ( 'ttl:a:*' , 0 , 1 ) ;
98
+ expect ( firstScanWithCount . keys ) . toEqual ( [ key1 ] ) ;
99
+ expect ( firstScanWithCount . cursor ) . not . equal ( 0 ) ;
100
+
101
+ const secondScanWithCount = await redisClient . scan ( 'ttl:a:*' , firstScanWithCount . cursor , 1 ) ;
102
+ expect ( secondScanWithCount . keys ) . toEqual ( [ key3 ] ) ;
103
+ expect ( secondScanWithCount . cursor ) . equal ( 3 ) ;
104
+
105
+ const thirdScanWithCount = await redisClient . scan ( 'ttl:a:*' , secondScanWithCount . cursor , 1 ) ;
106
+ expect ( thirdScanWithCount . keys ) . toEqual ( [ ] ) ;
107
+ expect ( thirdScanWithCount . cursor ) . equal ( 0 ) ;
108
+
96
109
} ) ;
97
110
} ) ;
You can’t perform that action at this time.
0 commit comments