Skip to content

Commit 1c9d95f

Browse files
author
phat
committed
feat(): skip redis replica server
1 parent 0bb24d7 commit 1c9d95f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/mix.heart/Services/RedisCacheClient.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
using Microsoft.Extensions.Caching.Distributed;
2-
using Mix.Heart.Extensions;
32
using Mix.Heart.Interfaces;
43
using StackExchange.Redis;
54
using System;
65
using System.Linq;
76
using System.Threading;
87
using System.Threading.Tasks;
9-
using System.Buffers.Text;
10-
using System.Text;
11-
using Newtonsoft.Json;
128
using Mix.Heart.Helpers;
139
namespace Mix.Heart.Services
1410
{
@@ -48,6 +44,12 @@ public async Task ClearCache(string key, CancellationToken cancellationToken = d
4844
foreach (var endpoint in endpoints)
4945
{
5046
var server = _connectionMultiplexer.GetServer(endpoint);
47+
48+
if (server.IsReplica || !server.IsConnected)
49+
{
50+
continue;
51+
}
52+
5153
await _database.KeyDeleteAsync(server.Keys(pattern: $"{key}:*").ToArray());
5254
}
5355
}
@@ -60,6 +62,12 @@ public async Task ClearAllCache(CancellationToken cancellationToken = default)
6062
foreach (var endpoint in endpoints)
6163
{
6264
var server = _connectionMultiplexer.GetServer(endpoint);
65+
66+
if (server.IsReplica || !server.IsConnected)
67+
{
68+
continue;
69+
}
70+
6371
await server.FlushDatabaseAsync();
6472
}
6573
}
@@ -74,4 +82,4 @@ public async Task ClearAllCache(CancellationToken cancellationToken = default)
7482

7583
#endregion
7684
}
77-
}
85+
}

0 commit comments

Comments
 (0)