I have a Nodejs application that I was using Redis for to handle the sessions. I am using connect-redis
npm package. Now, I deployed the same Nodejs app to heroku but I do not know if there is a way to get a Redis server going along side my Nodejs application in Heroku.
I get the following error on heroku logs --tail
2020-04-09T03:40:31.880266+00:00 app[web.1]: throw er; // Unhandled
‘error’ event 2020-04-09T03:40:31.880267+00:00 app[web.1]: ^
2020-04-09T03:40:31.880267+00:00 app[web.1]:
2020-04-09T03:40:31.880267+00:00 app[web.1]: Error: Redis connection
to 127.0.0.1:6379 failed – connect ECONNREFUSED 127.0.0.1:6379
2020-04-09T03:40:31.880268+00:00 app[web.1]: at
TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
2020-04-09T03:40:31.880268+00:00 app[web.1]: Emitted ‘error’ event on
RedisClient instance at: 2020-04-09T03:40:31.880268+00:00 app[web.1]:
at RedisClient.on_error (/app/node_modules/redis/index.js:341:14)
2020-04-09T03:40:31.880269+00:00 app[web.1]: at Socket.
(/app/node_modules/redis/index.js:222:14)
2020-04-09T03:40:31.880269+00:00 app[web.1]: at Socket.emit
(events.js:311:20) 2020-04-09T03:40:31.880269+00:00 app[web.1]: at
emitErrorNT (internal/streams/destroy.js:92:8)
2020-04-09T03:40:31.880270+00:00 app[web.1]: at emitErrorAndCloseNT
(internal/streams/destroy.js:60:3) 2020-04-09T03:40:31.880270+00:00
app[web.1]: at processTicksAndRejections
(internal/process/task_queues.js:84:21) {
2020-04-09T03:40:31.880278+00:00 app[web.1]: errno: ‘ECONNREFUSED’,
2020-04-09T03:40:31.880279+00:00 app[web.1]: code: ‘ECONNREFUSED’,
2020-04-09T03:40:31.880279+00:00 app[web.1]: syscall: ‘connect’,
2020-04-09T03:40:31.880279+00:00 app[web.1]: address: ‘127.0.0.1’,
2020-04-09T03:40:31.880280+00:00 app[web.1]: port: 6379
2020-04-09T03:40:31.880280+00:00 app[web.1]: }
I also added an addon called Heroku Redis but I get the same error message
2
Answers
On Heroku, your REDIS server is NO LONGER on 127.0.0.1
I’d recommend finding out the IP address of the Redis server on Heroku.
And change your Node.JS configuration for Redis server.
After three days looking for an answer to this error, I will share what worked for me, get the vision.
I’m using this Heroku Redis add-on you can install via heroku-cli or directly on the dashboard on the heroku website:
Resources> click Button "Find more add-ons" and search for Heroku Redis
Via heroku-cli:
heroku addons:create heroku-redis:hobby-dev
Create the BD Redis Get the variable data on the heroku page:
Resources> Add-ons> Heroku Redis> Settings
Create and configure as Redis environment variables in heroku:
REDIS_PASSWORD – provide a password generated by heroku:
REDIS_URL – provide a host created by heroku
REDIS_PORT – provide a port generated by heroku
Content of the Redis configuration file in the app:
redis.js
Reference: https://devcenter.heroku.com/articles