1

I used 2 pods and service on my Kubernetes cluster. They are Redis and my nodeJs application. Also I used scaffold for dev environment.

I want to connect Redis from my nodeJs application. I set environment variable on my nodeJs_app.yaml file for connection to Redis.

My nodeJs_app.yaml file look like:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nodeJsApp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: no
  template:
    metadata:
      labels:
        app: nodeJsApp
    spec:
      containers:
        - name: nodeJsApp
          image: nodeJsApp
          env:
            - name:  REDISCONNECTIONDEV
              value: "redis://redis-srv:6379/"
---
apiVersion: v1
kind: Service
metadata:
  name: nodeJsApp
spec:
  type: NodePort
  selector:
    app: nodeJsApp
  ports:
    - name: nodeJsApp
      protocol: TCP
      port: 3000
      nodePort: 30001

Also my Redis.yaml file like that:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
        - name: redis
          image: redis
---
apiVersion: v1
kind: Service
metadata:
  name: redis-srv
spec:
  selector:
    app: redis
  ports:
    - name: redis
      protocol: TCP
      port: 6379
      targetPort: 6379

I checked with kubectl get pods and kubectl get services and each services and ports running correctly.

On my NodeJs_app/index.js file I tried to connect Redis service with:

let REDIS_URL = process.env.REDISCONNECTIONDEV || production_redis_url;
let redisQueue = new Queue('my queue', REDIS_URL);

redisQueue('global:completed', (jobId, result) => {
    // console.log(`Job completed with result ${result}`);
});

But this situation return an error like that:

/app/node_modules/redis-parser/lib/parser.js:179
     return new ReplyError(string)
            ^
 
ReplyError: ERR value is not an integer or out of range
     at parseError (/app/node_modules/redis-parser/lib/parser.js:179:12)
     at parseType (/app/node_modules/redis-parser/lib/parser.js:302:14) {
   command: { name: 'select', args: [ 'NaN' ] }
 }

Also I'm new to Redis. Why this problem is occuring? How can I solve this?

akasaa
  • 1,282
  • 4
  • 13
  • 33

1 Answers1

3

Error occurs because you are trying to connect to redis database with NaN instead of number (number indicates database, 1-16). Check your code, because in some place you put NaN instead of number while trying to connect to redis database.

How to create own database in redis?

Marcin Warzybok
  • 357
  • 4
  • 16