On my node.js backend, I initialized a redis server:
const options = {
host: process.env.REDIS_HOST, // localhost
port: process.env.REDIS_PORT, // 6379 Redis standard port
db: 0,
// reconnect after
retryStrategy: times => Math.min(times * 50, 2000),
tls: {}
};
export const redis = new Redis(options);
Unfortunately, I always get this error message:
[ioredis] Unhandled error event: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/home/pascal/vipfy/vipfy-backend/node_modules/ioredis/built/redis.js:298:31)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.EventEmitter.emit (domain.js:442:20)
at TLSSocket.Socket._onTimeout (net.js:449:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
I installed redis locally and use the redis-cli to ping the local server, no password is set. It always gives a positive answer, but I can't seem to be able to reach it via ioredis. Anybody an idea?
Make sure your redis server is running. You just try without options params, so it will try to connect your localhost redis automatically by host as localhost
and port as 6379
.
redis = new Redis();
If you don't have any specific advantage try following, I am using following one and works well.
Package : "redis": "^2.8.0"
Code :
var redis = require('redis');
var redis_conn = redis.createClient();
redis_conn.set("key", "val");