Skip to content

Commit

Permalink
feat: update redis cluster constructor
Browse files Browse the repository at this point in the history
add required options to connect to redis cluster
  • Loading branch information
PAYNEA03 committed Jul 26, 2023
1 parent 06f1c5a commit a042a84
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 71 deletions.
40 changes: 26 additions & 14 deletions lib/redis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,40 @@ function getRedisConfiguration() {
export async function createRedisInstance(config = getRedisConfiguration()) {
try {
const options = {
host: config.host,
lazyConnect: true,
showFriendlyErrorStack: true,
enableAutoPipelining: true,
maxRetriesPerRequest: 0,
retryStrategy: times => {
if (times > 3) {
throw new Error(`[Redis] Could not connect after ${times} attempts`);
enableReadyCheck: true,
scaleReads: "all",
slotsRefreshTimeout: 5000,
redisOptions: {
host: config.host,
lazyConnect: true,
showFriendlyErrorStack: true,
enableAutoPipelining: true,
maxRetriesPerRequest: 0,
retryStrategy: times => {
if (times > 3) {
throw new Error(`[Redis] Could not connect after ${times} attempts`);
}

return Math.min(times * 200, 1000);
}

return Math.min(times * 200, 1000);
},
};
}

if (config.port) {
options.port = config.port;
options.redisOptions.port = config.port;
}

if (config.password) {
options.password = config.password;
options.redisOptions.password = config.password;
}

const redis = new Redis.Cluster(options);
const redis = new Redis.Cluster([
{
host: config.host,
port: config.port
}],
options
);

redis.on('error', error => {
console.warn('[Redis] Error connecting', error);
Expand Down Expand Up @@ -111,6 +122,7 @@ export async function cacheRead(key) {
if (!redisInstance) {
redisInstance = await createRedisInstance();
}
console.log(redisInstance)
const value = await redisInstance.get(key);
if (!value) return null;
const parsedValue = JSON.parse(value);
Expand Down
120 changes: 63 additions & 57 deletions site.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,83 @@ export const siteConfig = {
company: `airwalkreply.com`,
tagline: `technology, done right`,
etherpad: {
url: 'https://pad.airview.airwalkconsulting.io'
url: "https://pad.airview.airwalkconsulting.io",
},
content: {
services: {
source: 'github', // The source of the content
repo: 'airwalk_patterns', // The name of the repo
owner: 'airwalk-digital', // The owner of the repo
branch: '1-rob-ellison',
path: 'services', // the base path for the content
reference: 'service', // how the collection is referred to in frontmatter links
collections: ['knowledge', 'designs']

source: "github", // The source of the content
repo: "airview-demo-content", // The name of the repo
owner: "airwalk-digital", // The owner of the repo
branch: "main",
path: "services", // the base path for the content
reference: "service", // how the collection is referred to in frontmatter links
collections: ["knowledge", "designs"],
},
providers: {
source: 'github', // The source of the content
repo: 'airwalk_patterns', // The name of the repo
owner: 'airwalk-digital', // The owner of the repo
branch: '1-rob-ellison',
path: 'providers', // the base path for the content
reference: 'provider', // how the collection is referred to in frontmatter links
collections: ['services']
source: "github", // The source of the content
repo: "airview-demo-content", // The name of the repo
owner: "airwalk-digital", // The owner of the repo
branch: "main",
path: "providers", // the base path for the content
reference: "provider", // how the collection is referred to in frontmatter links
collections: ["services"],
},
solutions: {
source: 'github', // The source of the content
repo: 'airwalk_patterns', // The name of the repo
owner: 'airwalk-digital', // The owner of the repo
branch: '1-rob-ellison',
path: 'solutions', // the base path for the content
reference: 'solution', // how the collection is referred to in frontmatter links
collections: ['knowledge', 'designs']

source: "github", // The source of the content
repo: "airview-demo-content", // The name of the repo
owner: "airwalk-digital", // The owner of the repo
branch: "main",
path: "solutions", // the base path for the content
reference: "solution", // how the collection is referred to in frontmatter links
collections: ["knowledge", "designs"],
},
knowledge: {
source: 'github', // The source of the content
repo: 'airwalk_patterns', // The name of the repo
owner: 'airwalk-digital', // The owner of the repo
branch: 'main',
path: 'knowledge', // the base path for the content
reference: 'knowledge', // how the collection is referred to in frontmatter links
source: "github", // The source of the content
repo: "airview-demo-content", // The name of the repo
owner: "airwalk-digital", // The owner of the repo
branch: "main",
path: "knowledge", // the base path for the content
reference: "knowledge", // how the collection is referred to in frontmatter links
},
designs: {
source: 'github', // The source of the content
repo: 'airwalk_patterns', // The name of the repo
owner: 'airwalk-digital', // The owner of the repo
branch: 'main',
path: 'designs', // the base path for the content
reference: 'design', // how the collection is referred to in frontmatter links
collections: ['knowledge']
source: "github", // The source of the content
repo: "airview-demo-content", // The name of the repo
owner: "airwalk-digital", // The owner of the repo
branch: "main",
path: "designs", // the base path for the content
reference: "design", // how the collection is referred to in frontmatter links
collections: ["knowledge"],
},
customers: {
source: 'github', // The source of the content
repo: 'airwalk_patterns', // The name of the repo
owner: 'airwalk-digital', // The owner of the repo
branch: 'main',
path: 'customers', // the base path for the content
reference: 'customer', // how the collection is referred to in frontmatter links
collections: ['knowledge', 'projects']
source: "github", // The source of the content
repo: "airview-demo-content", // The name of the repo
owner: "airwalk-digital", // The owner of the repo
branch: "main",
path: "customers", // the base path for the content
reference: "customer", // how the collection is referred to in frontmatter links
collections: ["knowledge", "projects"],
},
projects: {
source: 'github', // The source of the content
repo: 'airwalk_patterns', // The name of the repo
owner: 'airwalk-digital', // The owner of the repo
branch: 'main',
path: 'projects', // the base path for the content
reference: 'project', // how the collection is referred to in frontmatter links
collections: ['knowledge']
source: "github", // The source of the content
repo: "airview-demo-content", // The name of the repo
owner: "airwalk-digital", // The owner of the repo
branch: "main",
path: "projects", // the base path for the content
reference: "project", // how the collection is referred to in frontmatter links
collections: ["knowledge"],
},
applications: { source: 'static'},
frameworks: { source: 'static'}
}

}
products: {
source: "github", // The source of the content
repo: "airview-demo-content", // The name of the repo
owner: "airwalk-digital", // The owner of the repo
branch: "main",
path: "products", // the base path for the content
reference: "product", // how the collection is referred to in frontmatter links
collections: ["knowledge", "designs"],
},
applications: { source: "static" },
frameworks: { source: "static" },
},
};

export default siteConfig
export default siteConfig;

0 comments on commit a042a84

Please sign in to comment.