Skip to content

Instantly share code, notes, and snippets.

@GoodnessEzeokafor
Created September 15, 2024 11:52
Show Gist options
  • Save GoodnessEzeokafor/d678520eef7330e5941450bc6a17b78e to your computer and use it in GitHub Desktop.
Save GoodnessEzeokafor/d678520eef7330e5941450bc6a17b78e to your computer and use it in GitHub Desktop.
/**
* 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