Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit c1c5d1e

Browse files
committed
Update RedisStats to include Retry Counts and Resets
1 parent c105c76 commit c1c5d1e

File tree

3 files changed

+72
-10
lines changed

3 files changed

+72
-10
lines changed

src/ServiceStack.Redis/RedisConfig.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,29 @@ public class RedisConfig
4444
//Example at: http://msdn.microsoft.com/en-us/library/office/dd633677(v=exchg.80).aspx
4545
public static LocalCertificateSelectionCallback CertificateSelectionCallback { get; set; }
4646
public static RemoteCertificateValidationCallback CertificateValidationCallback { get; set; }
47+
48+
/// <summary>
49+
/// Resets Redis Config and Redis Stats back to default values
50+
/// </summary>
51+
public static void Reset()
52+
{
53+
RedisStats.Reset();
54+
55+
DefaultConnectTimeout = 0;
56+
DefaultSendTimeout = -1;
57+
DefaultReceiveTimeout = -1;
58+
DefaultRetryTimeout = 3 * 1000;
59+
DefaultIdleTimeOutSecs = 240;
60+
BackOffMultiplier = 10;
61+
BufferLength = 1450;
62+
BufferPoolMaxSize = 500000;
63+
VerifyMasterConnections = true;
64+
HostLookupTimeoutMs = 200;
65+
AssumeServerVersion = null;
66+
DeactivatedClientsExpiry = TimeSpan.FromMinutes(1);
67+
DisableVerboseLogging = false;
68+
CertificateSelectionCallback = null;
69+
CertificateValidationCallback = null;
70+
}
4771
}
4872
}

src/ServiceStack.Redis/RedisState.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ internal static class RedisState
2424
internal static long TotalClientsCreatedOutsidePool = 0;
2525
internal static long TotalSubjectiveServersDown = 0;
2626
internal static long TotalObjectiveServersDown = 0;
27+
internal static long TotalRetryCount = 0;
28+
internal static long TotalRetrySuccess = 0;
29+
internal static long TotalRetryTimedout = 0;
2730

2831
internal static readonly ConcurrentDictionary<RedisClient, DateTime> DeactivatedClients = new ConcurrentDictionary<RedisClient, DateTime>();
2932

src/ServiceStack.Redis/RedisStats.cs

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,84 @@ public static class RedisStats
77
{
88
public static long TotalFailovers
99
{
10-
get { return Interlocked.CompareExchange(ref RedisState.TotalFailovers, 0, 0); }
10+
get { return Interlocked.Read(ref RedisState.TotalFailovers); }
1111
}
1212

1313
public static long TotalDeactivatedClients
1414
{
15-
get { return Interlocked.CompareExchange(ref RedisState.TotalDeactivatedClients, 0, 0); }
15+
get { return Interlocked.Read(ref RedisState.TotalDeactivatedClients); }
1616
}
1717

1818
public static long TotalFailedSentinelWorkers
1919
{
20-
get { return Interlocked.CompareExchange(ref RedisState.TotalFailedSentinelWorkers, 0, 0); }
20+
get { return Interlocked.Read(ref RedisState.TotalFailedSentinelWorkers); }
2121
}
2222

2323
public static long TotalForcedMasterFailovers
2424
{
25-
get { return Interlocked.CompareExchange(ref RedisState.TotalForcedMasterFailovers, 0, 0); }
25+
get { return Interlocked.Read(ref RedisState.TotalForcedMasterFailovers); }
2626
}
2727

2828
public static long TotalInvalidMasters
2929
{
30-
get { return Interlocked.CompareExchange(ref RedisState.TotalInvalidMasters, 0, 0); }
30+
get { return Interlocked.Read(ref RedisState.TotalInvalidMasters); }
3131
}
3232

3333
public static long TotalNoMastersFound
3434
{
35-
get { return Interlocked.CompareExchange(ref RedisState.TotalNoMastersFound, 0, 0); }
35+
get { return Interlocked.Read(ref RedisState.TotalNoMastersFound); }
3636
}
3737

3838
public static long TotalClientsCreated
3939
{
40-
get { return Interlocked.CompareExchange(ref RedisState.TotalClientsCreated, 0, 0); }
40+
get { return Interlocked.Read(ref RedisState.TotalClientsCreated); }
4141
}
4242

4343
public static long TotalClientsCreatedOutsidePool
4444
{
45-
get { return Interlocked.CompareExchange(ref RedisState.TotalClientsCreatedOutsidePool, 0, 0); }
45+
get { return Interlocked.Read(ref RedisState.TotalClientsCreatedOutsidePool); }
4646
}
4747

4848
public static long TotalSubjectiveServersDown
4949
{
50-
get { return Interlocked.CompareExchange(ref RedisState.TotalSubjectiveServersDown, 0, 0); }
50+
get { return Interlocked.Read(ref RedisState.TotalSubjectiveServersDown); }
5151
}
5252

5353
public static long TotalObjectiveServersDown
5454
{
55-
get { return Interlocked.CompareExchange(ref RedisState.TotalObjectiveServersDown, 0, 0); }
55+
get { return Interlocked.Read(ref RedisState.TotalObjectiveServersDown); }
56+
}
57+
58+
public static long TotalRetryCount
59+
{
60+
get { return Interlocked.Read(ref RedisState.TotalRetryCount); }
61+
}
62+
63+
public static long TotalRetrySuccess
64+
{
65+
get { return Interlocked.Read(ref RedisState.TotalRetrySuccess); }
66+
}
67+
68+
public static long TotalRetryTimedout
69+
{
70+
get { return Interlocked.Read(ref RedisState.TotalRetryTimedout); }
71+
}
72+
73+
public static void Reset()
74+
{
75+
Interlocked.Exchange(ref RedisState.TotalFailovers, 0);
76+
Interlocked.Exchange(ref RedisState.TotalDeactivatedClients, 0);
77+
Interlocked.Exchange(ref RedisState.TotalFailedSentinelWorkers, 0);
78+
Interlocked.Exchange(ref RedisState.TotalForcedMasterFailovers, 0);
79+
Interlocked.Exchange(ref RedisState.TotalInvalidMasters, 0);
80+
Interlocked.Exchange(ref RedisState.TotalNoMastersFound, 0);
81+
Interlocked.Exchange(ref RedisState.TotalClientsCreated, 0);
82+
Interlocked.Exchange(ref RedisState.TotalClientsCreatedOutsidePool, 0);
83+
Interlocked.Exchange(ref RedisState.TotalSubjectiveServersDown, 0);
84+
Interlocked.Exchange(ref RedisState.TotalObjectiveServersDown, 0);
85+
Interlocked.Exchange(ref RedisState.TotalRetryCount, 0);
86+
Interlocked.Exchange(ref RedisState.TotalRetrySuccess, 0);
87+
Interlocked.Exchange(ref RedisState.TotalRetryTimedout, 0);
5688
}
5789

5890
public static Dictionary<string, long> ToDictionary()
@@ -70,6 +102,9 @@ public static Dictionary<string, long> ToDictionary()
70102
{"TotalSubjectiveServersDown", TotalSubjectiveServersDown},
71103
{"TotalObjectiveServersDown", TotalObjectiveServersDown},
72104
{"TotalPendingDeactivatedClients", RedisState.DeactivatedClients.Count },
105+
{"TotalRetryCount", TotalRetryCount },
106+
{"TotalRetrySuccess", TotalRetrySuccess },
107+
{"TotalRetryTimedout", TotalRetryTimedout },
73108
};
74109
}
75110
}

0 commit comments

Comments
 (0)