1+ using Enyim . Caching . Configuration ;
12using System ;
2- using System . Linq ;
33using System . Collections . Generic ;
4+ using System . Linq ;
45using System . Net ;
56
67namespace Enyim . Caching . Memcached
@@ -17,6 +18,7 @@ public sealed class ServerStats
1718 /// Defines a value which indicates that the statstics should be retrieved for all servers in the pool.
1819 /// </summary>
1920 public static readonly IPEndPoint All = new IPEndPoint ( IPAddress . Any , 0 ) ;
21+
2022 #region [ readonly int[] Optable ]
2123 // defines which values can be summed and which not
2224 private static readonly int [ ] Optable =
@@ -25,6 +27,7 @@ public sealed class ServerStats
2527 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1
2628 } ;
2729 #endregion
30+
2831 #region [ readonly string[] StatKeys ]
2932 private static readonly string [ ] StatKeys =
3033 {
@@ -47,11 +50,14 @@ public sealed class ServerStats
4750 } ;
4851 #endregion
4952
50- private Dictionary < EndPoint , Dictionary < string , string > > _results ;
53+ private readonly Dictionary < EndPoint , Dictionary < string , string > > _results ;
5154
52- internal ServerStats ( Dictionary < EndPoint , Dictionary < string , string > > results )
55+ private readonly bool _useIPv6 ;
56+
57+ internal ServerStats ( Dictionary < EndPoint , Dictionary < string , string > > results , bool useIPv6 )
5358 {
5459 _results = results ;
60+ _useIPv6 = useIPv6 ;
5561 }
5662
5763 /// <summary>
@@ -62,12 +68,14 @@ internal ServerStats(Dictionary<EndPoint, Dictionary<string, string>> results)
6268 /// <returns>The value of the specified stat item</returns>
6369 public long GetValue ( EndPoint server , StatItem item )
6470 {
71+ server = server . GetIPEndPoint ( _useIPv6 ) ;
72+
6573 // asked for a specific server
6674 if ( server is not IPEndPoint || ( ( IPEndPoint ) server ) . Address != IPAddress . Any )
6775 {
6876 // error check
6977 string tmp = GetRaw ( server , item ) ;
70- if ( String . IsNullOrEmpty ( tmp ) )
78+ if ( string . IsNullOrEmpty ( tmp ) )
7179 throw new ArgumentException ( "Item was not found: " + item ) ;
7280
7381 long value ;
@@ -100,8 +108,9 @@ public long GetValue(EndPoint server, StatItem item)
100108 /// <returns>The version of memcached</returns>
101109 public Version GetVersion ( EndPoint server )
102110 {
111+ server = server . GetIPEndPoint ( _useIPv6 ) ;
103112 string version = GetRaw ( server , StatItem . Version ) ;
104- if ( String . IsNullOrEmpty ( version ) )
113+ if ( string . IsNullOrEmpty ( version ) )
105114 throw new ArgumentException ( "No version found for the server " + server ) ;
106115
107116 return new Version ( version ) ;
@@ -114,12 +123,13 @@ public Version GetVersion(EndPoint server)
114123 /// <returns>A value indicating how long the server is running</returns>
115124 public TimeSpan GetUptime ( EndPoint server )
116125 {
126+ server = server . GetIPEndPoint ( _useIPv6 ) ;
117127 string uptime = GetRaw ( server , StatItem . Uptime ) ;
118- if ( String . IsNullOrEmpty ( uptime ) )
128+ if ( string . IsNullOrEmpty ( uptime ) )
119129 throw new ArgumentException ( "No uptime found for the server " + server ) ;
120130
121131 long value ;
122- if ( ! Int64 . TryParse ( uptime , out value ) )
132+ if ( ! long . TryParse ( uptime , out value ) )
123133 throw new ArgumentException ( "Invalid uptime string was returned: " + uptime ) ;
124134
125135 return TimeSpan . FromSeconds ( value ) ;
@@ -133,12 +143,11 @@ public TimeSpan GetUptime(EndPoint server)
133143 /// <returns>The value of the stat item</returns>
134144 public string GetRaw ( EndPoint server , string key )
135145 {
136- Dictionary < string , string > serverValues ;
137- string retval ;
146+ server = server . GetIPEndPoint ( _useIPv6 ) ;
138147
139- if ( _results . TryGetValue ( server , out serverValues ) )
148+ if ( _results . TryGetValue ( server , out Dictionary < string , string > serverValues ) )
140149 {
141- if ( serverValues . TryGetValue ( key , out retval ) )
150+ if ( serverValues . TryGetValue ( key , out string retval ) )
142151 return retval ;
143152
144153 if ( _log . IsDebugEnabled )
@@ -161,17 +170,17 @@ public string GetRaw(EndPoint server, string key)
161170 /// <returns>The value of the stat item</returns>
162171 public string GetRaw ( EndPoint server , StatItem item )
163172 {
173+ server = server . GetIPEndPoint ( _useIPv6 ) ;
174+
164175 if ( ( int ) item < StatKeys . Length && ( int ) item >= 0 )
165176 return GetRaw ( server , StatKeys [ ( int ) item ] ) ;
166177
167- throw new ArgumentOutOfRangeException ( " item" ) ;
178+ throw new ArgumentOutOfRangeException ( nameof ( item ) ) ;
168179 }
169180
170181 public IEnumerable < KeyValuePair < EndPoint , string > > GetRaw ( string key )
171182 {
172- string tmp ;
173-
174- return _results . Select ( kvp => new KeyValuePair < EndPoint , string > ( kvp . Key , kvp . Value . TryGetValue ( key , out tmp ) ? tmp : null ) ) . ToList ( ) ;
183+ return _results . Select ( kvp => new KeyValuePair < EndPoint , string > ( kvp . Key , kvp . Value . TryGetValue ( key , out string tmp ) ? tmp : null ) ) . ToList ( ) ;
175184 }
176185 }
177186}
0 commit comments