I am not sure what to title my question.
Its been a adventure with node.js and a helpful person pointed me to ioredis. Currently I have:
var Redis = require("ioredis");
const DBConfig = require(__dirname+'/../Config.json');
var cluster = new Redis.Cluster([
{
port: 6001,
host: "10.0.0.6",
},
{
port: 6002,
host: "10.0.0.5",
},
{
port: 6003,
host: "10.0.0.4",
},
{
port: 6004,
host: "10.0.0.3",
},
{
port: 6005,
host: "10.0.0.2",
},
{
port: 6006,
host: "10.0.0.1",
},
]);
But to me this seems it would be better in a json config file like…
Config.json:
{
"configA" : "abc",
"someotherconfigB" : "Stuff",
"foo" : "bar"
}
{
"port": 6001,
"host": "10.0.0.6",
},
{
"port": 6002,
"host": "10.0.0.5",
},
{
"port": 6003,
"host": "10.0.0.4",
},
{
"port": 6004,
"host": "10.0.0.3",
},
{
"port": 6005,
"host": "10.0.0.2",
},
{
"port": 6006,
"host": "10.0.0.1",
},
}
I am so new and this I just not sure how to implement this without syntax errors.
var Redis = require("ioredis");
const DBConfig = require(__dirname+'/../Config.json');
var cluster = new Redis.Cluster([DBConfig.redis]);
I am not sure how to implement “var cluster = new Redis.Cluster([DBConfig.redis]);” properly
2
Answers
You should declare those settings in as an array under a key
Then use that key to access that value inside the required config file.
First, you need to have a proper config file. Your file seems to contain some config information and node information. I would suggest:
Config.json
file:Then your file should look like:
DBConfig.nodes
it’s already an array. No need to put brackets around itObject.entries(DBConfig.configs)
will give you an array of [key, value] pairs of yourDBConfig.configs
‘s propertiesResources:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries