[英]How to connect AWS elasticache redis from Node.js application?
如何从 Node.js 应用程序连接 AWS elasticache redis?
您可以使用 package ioredis
并建立这样的连接
const Redis = require('ioredis')
const redis = new Redis({
port: 6379,
host: 'your-redis-host',
connectTimeout: 10000 // optional
});
您可以尝试使用 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); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.