nestjs-redis icon indicating copy to clipboard operation
nestjs-redis copied to clipboard

(feature request) Redis Interceptor

Open bashleigh opened this issue 5 years ago • 4 comments

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

bashleigh avatar Aug 04 '19 09:08 bashleigh

Oh Welcome,That's great! Thank you!

skunight avatar Aug 05 '19 02:08 skunight

Cool :) I'll make a PR soon!

bashleigh avatar Aug 05 '19 09:08 bashleigh

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

bashleigh avatar Aug 22 '19 08:08 bashleigh

OK,I will test this PR

skunight avatar Sep 04 '19 02:09 skunight