Skip to content

Commit

Permalink
Merge pull request #18 from imRohan/hotfix/redisScanCount
Browse files Browse the repository at this point in the history
Removed Redis cursor validation, added count argument
  • Loading branch information
Rohan Likhite authored Apr 30, 2020
2 parents 4c355b5 + f6bdf1b commit ce04777
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/models/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Account {

public async getBlocks(): Promise<string[]> {
const _accountKey = Account.generateRedisKey(this.uuid)
const _blocks = await dataStore.scan(`${_accountKey}::block:*`)
const _blocks = await dataStore.scan(`${_accountKey}::block:*`, this.maxNumberOfBlocks)

const _blocksSanitized = _blocks.map((block) => {
return block.split(':')[4]
Expand Down
8 changes: 2 additions & 6 deletions src/services/dataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,13 @@ const dataStore = {
}
},

async scan(pattern: string): Promise<string[]> {
async scan(pattern: string, count: number): Promise<string[]> {
try {
const _redisClient = redis.createClient()
const _scan = promisify(_redisClient.scan).bind(_redisClient)
const [ _cursor, _storedKeys ] = await _scan(0, 'MATCH', pattern)
const [ , _storedKeys ] = await _scan(0, 'MATCH', pattern, 'COUNT', count)
_redisClient.quit()

if (Number(_cursor) !== 0) {
throw new Error(`cursor returned invalid value: ${_cursor}`)
}

return _storedKeys
} catch (error) {
logger.error(`Error when scanning keys: ${error.message}`)
Expand Down

0 comments on commit ce04777

Please sign in to comment.