小编Max*_*ax 的帖子

Redis在docker中未定义

我正在构建 GraphQL API,并且想对某些解析器进行速率限制。为此,我使用此速率限制器: https: //github.com/teamplanes/graphql-rate-limit

这就是我的实现方式:

import { createRateLimitRule, RedisStore } from 'graphql-rate-limit';
import redis from 'redis'

const rateLimit = createRateLimitRule({ 
  identifyContext: (ctx) => ctx.req.ip, 
  formatError: () => `Hey there, you are doing way too much`,
  store: new RedisStore(redis.createClient(6379, 'redis'))
});
Run Code Online (Sandbox Code Playgroud)

但是当我运行时,docker-compose up我的 NodeJS 应用程序出现此错误:
TypeError: Cannot read property 'createClient' of undefined

我的 PostgreSQL 数据库和 NodeJS 应用程序都正常启动。

这是我的 docker-compose 文件:

version: "3.7"
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 4000:4000
    depends_on: 
      - postgres
      - redis
    env_file: …
Run Code Online (Sandbox Code Playgroud)

redis node.js docker graphql

1
推荐指数
1
解决办法
1475
查看次数

标签 统计

docker ×1

graphql ×1

node.js ×1

redis ×1