Created
September 15, 2024 11:52
-
-
Save GoodnessEzeokafor/d678520eef7330e5941450bc6a17b78e to your computer and use it in GitHub Desktop.
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
/** | |
* gets the userId | |
* creates a redis key(identifier) | |
* checks if the key exists | |
* returns the data instead | |
*/ | |
const redisKey = `transactions-v3-${userId}-${JSON.stringify(payload)}`; | |
const redisValue = await this.cache.get(redisKey); | |
if (redisValue) { | |
return this.response.success200Response({ | |
message: 'Retrieved successfully', | |
...JSON.parse(redisValue), | |
}); | |
} | |
const { data, pagination } = | |
await this.data.transactions.findAllWithPagination( | |
{ | |
...filterQuery, | |
isRevenue: false, | |
reconTransactionType: Not(In(excludedTransactionType)), | |
}, | |
{ | |
relationFields: ['user'], | |
selectFields: this.selectFields, | |
}, | |
); | |
// stores the data retrieved from the database for 30 seconds | |
await this.cache.set( | |
redisKey, | |
JSON.stringify({ data, pagination }), | |
this.time.convertToSeconds('minute', 0.5), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment