3

How to connect AWS elasticache redis from Node.js application ?

asked May 20, 2020 at 20:09

3 Answers 3

1

You're connecting to Redis. The fact that it's a managed AWS service is not really that important in this respect.

So, use a Node.js package that implements a Redis client interface, for example:

answered May 21, 2020 at 0:31
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the package ioredis and stablish a connection like this

 const Redis = require('ioredis')
 const redis = new Redis({
 port: 6379,
 host: 'your-redis-host',
 connectTimeout: 10000 // optional
 });
answered Aug 9, 2021 at 19:01

Comments

0

You can try connecting using ioredis.

var Redis = require('ioredis');
var config = require("./config.json");
const redis = new Redis({
 host: config.host,
 port: config.port,
 password: config.password, // If you have any.
 tls: {}, // Add this empty tls field.
});
redis.on('connect', () => {
 console.log('Redis client is initiating a connection to the server.');
});
redis.on('ready', () => {
 console.log('Redis client successfully initiated connection to the server.');
});
redis.on('reconnecting', () => {
 console.log('Redis client is trying to reconnect to the server...');
});
redis.on('error', (err) => console.log('Redis Client Error', err));
//check the functioning
redis.set("framework", "AngularJS", function(err, reply) {
 console.log("redis.set ", reply);
});
redis.get("framework", function(err, reply) {
 console.log("redis.get ", reply);
});

answered Jul 5, 2022 at 5:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.