Skip to content

Commit

Permalink
fix(redis): Show warning when using Redis Cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Dec 15, 2023
1 parent 814e724 commit 17b599e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/lua/s-list-accounts.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- NB!
-- This script is not compatible with Redis clustering if using account id as the hash slot key

local listKey = KEYS[1];

local filterState = ARGV[1];
Expand Down
1 change: 1 addition & 0 deletions lib/routes-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ function applyRoutes(server, call) {
hasAccounts,

isElastiCache: ['elasticache'].includes(stats.redisSoftware),
isRedisCluster: stats.redisCluster,

redisPing: {
key: 'redisPing',
Expand Down
14 changes: 14 additions & 0 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -1126,13 +1126,20 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
let redisVersion;
let softwareDetails;
let redisSoftware;
let redisCluster = false;

try {
let redisInfo = await module.exports.getRedisStats(redis);

if (!redisInfo || typeof redisInfo.redis_version !== 'string') {
throw new Error('Failed to fetch Redis INFO');
}
redisVersion = redisInfo.redis_version;

if (redisInfo.cluster_enabled && Number(redisInfo.cluster_enabled) && !isNaN(redisInfo.cluster_enabled) && redisInfo.cluster_enabled > 0) {
redisCluster = true;
}

// Detect Dragonfly
if (typeof redisInfo.dragonfly_version === 'string') {
softwareDetails = `Dragonfly v${redisInfo.dragonfly_version.replace(/^[^\d]*/, '')}`;
Expand Down Expand Up @@ -1162,6 +1169,12 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
softwareDetails = `Amazon ElastiCache`;
redisSoftware = 'elasticache';
}

// Detect MemoryDB
if (/Amazon MemoryDB/i.test(redisInfo.os)) {
softwareDetails = `Amazon MemoryDB`;
redisSoftware = 'memorydb';
}
} catch (err) {
console.log(err);
// ignore
Expand Down Expand Up @@ -1205,6 +1218,7 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
node: process.versions.node,
redis: `${redisVersion}${softwareDetails ? ` (${softwareDetails})` : ''}`,
redisSoftware,
redisCluster,
imapflow: ImapFlow.version || 'please upgrade',
bullmq: bullmqPackage.version,
arch: process.arch,
Expand Down
19 changes: 19 additions & 0 deletions views/dashboard.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@
{{/if}}


{{#if isRedisCluster}}
<div class="card border-left-danger mt-4">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-danger text-uppercase mb-1">Compatiblity warning
</div>
<p>EmailEngine is incompatible with Redis Cluster setup.</p>
<p>Please switch to a standard Redis primary instance.</p>
</div>
<div class="col-auto">
<i class="fas fa-exclamation-circle fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
{{/if}}


{{#unless hasAccounts}}

<div class="card border-left-success mt-4">
Expand Down

0 comments on commit 17b599e

Please sign in to comment.