繁体   English   中英

如何从 Node.js 应用程序连接 AWS elasticache redis?

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

如何从 Node.js 应用程序连接 AWS elasticache redis?

您正在连接到 Redis。 在这方面,它是一项托管 AWS 服务这一事实并不那么重要。

因此,请使用实现 Redis 客户端接口的 Node.js package,例如:

您可以使用 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM