Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ioredis connect aws cluster redis #1887

Open
cat1314e opened this issue Apr 25, 2024 · 1 comment
Open

ioredis connect aws cluster redis #1887

cat1314e opened this issue Apr 25, 2024 · 1 comment

Comments

@cat1314e
Copy link

cat1314e commented Apr 25, 2024

aws cluster redis need SSL set true to connect,

my code is this:

const Redis = require('ioredis');

const clusterNodes = [
  {
    host: 'clustercfg.***-dev-redis-rg-01.7duglj.apne1.cache.amazonaws.com',
    port: 6379,
    password: "#####",
  },
];

// create Redis cluster
const cluster = new Redis.Cluster(clusterNodes, {
  redisOptions: {
    tls: {},
  },
 dnsLookup: (address, callback) => callback(null, address),
});

// test connect
cluster.on('connect', () => {
  console.log('Connected success');
});

cluster.on('error', (err) => {
  console.error('error====:', err);
});

// set key
cluster.set('mykey', 'Hello Redis Cluster', (err, result) => {
  if (err) {
    console.error('Error setting key:', err);
  } else {
    console.log('Key set successfully:', result);
  }
});
cluster.get('mykey', (err, result) => {
  if (err) {
    console.error('Error setting key:', err);
  } else {
    console.log('Key set successfully:', result);
  }
});
// close
// cluster.quit();

This is terminal print:

=====redis error== ClusterAllFailedError: Failed to refresh slots cache.
    at tryNode (C:\Users\cat1314e\Desktop\production\pnec-bff\node_modules\ioredis\built\cluster\index.js:310:31)
    at C:\Users\cat1314e\Desktop\production\pnec-bff\node_modules\ioredis\built\cluster\index.js:327:21
    at C:\Users\cat1314e\Desktop\production\pnec-bff\node_modules\ioredis\built\cluster\index.js:664:24
    at run (C:\Users\cat1314e\Desktop\production\pnec-bff\node_modules\ioredis\built\utils\index.js:117:22)
    at tryCatcher (C:\Users\cat1314e\Desktop\production\pnec-bff\node_modules\standard-as-callback\built\utils.js:12:23)
    at C:\Users\cat1314e\Desktop\production\pnec-bff\node_modules\standard-as-callback\built\index.js:33:51
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  lastNodeError: Error: error:0909006C:PEM routines:get_name:no start line
      at Object.createSecureContext (_tls_common.js:149:17)
      at connect (_tls_wrap.js:1606:48)
      at C:\Users\cat1314e\Desktop\production\pnec-bff\node_modules\ioredis\built\connectors\StandaloneConnector.js:51:57
      at processTicksAndRejections (internal/process/task_queues.js:77:11) {
    library: 'PEM routines',
    function: 'get_name',
    reason: 'no start line',
    code: 'ERR_OSSL_PEM_NO_START_LINE'
  }
}

This is my local use app Another Redis Desktop Manager connect screenshot:
_17140229908068
17140231363558

questions: I want know how i set ioredis ssl configuration can connect aws cluster redis?

@renarsvilnis
Copy link

renarsvilnis commented May 3, 2024

@cat1314e the documentation should work, using it in production, but we are passing password within redisOption
https://github.com/redis/ioredis?tab=readme-ov-file#special-note-aws-elasticache-clusters-with-tls

new Redis.Cluster(
  [
    {
      host: config.redis.host,
      port: config.redis.port,
    },
  ],
  {
    // @see: https://github.com/luin/ioredis#special-note-aws-elasticache-clusters-with-tls
    dnsLookup: (address, callback) => callback(null, address),
    redisOptions: {
      tls: {},
      password: config.redis.authToken,
    },
  }
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants