【问题标题】:In NestJs, I added Redis as cache manager, when I specify {ttl : 0} it throws a type error, it was working before在 NestJs 中,我将 Redis 添加为缓存管理器,当我指定 {ttl : 0} 时它会抛出类型错误,它之前是工作的
【发布时间】:2022-11-26 22:04:22
【问题描述】:

我在 NestJs 项目中使用 Redis 作为缓存管理器。我使用的代码如下:

await this.productCacheManager.set('products/time', data, { ttl: 60} )

当我删除 ttl 参数或只是将 60 放在那里时,它不起作用,它会立即从 redis 中删除记录,所以我使用的是 { ttl: 60} ,它一直工作到现在。 我不知道发生了什么,但现在它抛出如下错误:

'{ ttl: number; 类型的参数}' 不可分配给类型为“数字”的参数。

我输入的参数是一个数字...

试图让它像以前一样再次工作。

【问题讨论】:

    标签: redis nestjs


    【解决方案1】:

    你只需要传递数字,而不是对象{ ttl: 60},只需要使用60,因为这里它只保留给til并且它知道它会是一个数字。

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-09
      • 2023-04-06
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多