nestjs-redis
nestjs-redis copied to clipboard
(feature request) Redis Interceptor
Hey! Thanks for all the hard work you've made on this package!
I used this package in a code test recently and I built a redis interceptor for caching my routes responses.
It might be handy for others to use this interceptor so I was going to ask, would you like me to add a PR to add the interceptor?
I used it like this
@Controller()
export class TestController {
constructor (private readonly api: SomeApiClientOrWhatever) {}
@Get('some/path')
@UseInterceptor(RedisInterceptor)
async cacheMe(@Query('page') page: number = 1, @Query('limit') limit: number = 10): Promise<SomeObject[]> {
return await this.api.get(`get/loads/of/things?page=${page}&per_page=${limit}`);
}
}
The above would cache the response of cacheMe
using the request url + method as the key like so GET.some/path?page=1&limit=10
or GET.some/path
. When the cache key exists on a second request, the cache is used rather than calling the method a second time
Oh Welcome,That's great! Thank you!
Cool :) I'll make a PR soon!
Hey! Sorry for long delay. Long story short I quit a job and got another one in the space of 5 days changed laptops 3 times and I've been waiting to get some free time with the laptop the PR is currently on to push to the repo so I can work on it on another machine.
Also, been struggling with your tests setup. Are you ok if I submit a PR without tests? Or with tests that should pass but I can't run? X'D
OK,I will test this PR