ioredis
ioredis copied to clipboard
ioredis connect aws cluster redis
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:
questions: I want know how i set ioredis ssl configuration can connect aws cluster redis?
@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,
},
}
);