Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Connecting to redis cluster

There are tons of examples and resources for connecting to a redis "server" but not to a redis "cluster".

What I currently have is:

const redis = require("redis"); 
const client = redis.createClient({
 port      : 6379,               // replace with your port
 host      : '10.0.0.100',        // replace with your hostanme or IP address
 password  : 'Notforyou',    // replace with your password
 // optional, if using SSL
 // use `fs.readFile[Sync]` or another method to bring these values in
 tls       : {
   key  : stringValueOfKeyFile,  
   cert : stringValueOfCertFile,
   ca   : [ stringValueOfCaCertFile ]
 }
});

But this is for a single redis server not a cluster. How would I go about connecting to my cluster?

like image 551
MoonEater916 Avatar asked Aug 11 '26 15:08

MoonEater916


1 Answers

The Readme tab in redis npm package has this link(Clustering Guide) explaining how to connect to redis cluster with node under heading 'Clustering'. It's very simple, create a cluster instead of creating client and configure the nodes url as given in this example

like image 134
Aravinth Avatar answered Aug 14 '26 11:08

Aravinth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!