This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
tests/ServiceStack.Redis.Tests Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public partial class RedisNativeClient
26
26
{
27
27
private static Timer UsageTimer ;
28
28
private static int __requestsPerHour = 0 ;
29
+ private const int Unknown = - 1 ;
29
30
public int ServerVersionNumber { get ; set ; }
30
31
31
32
public static void DisposeTimers ( )
@@ -91,7 +92,7 @@ private void Connect()
91
92
if ( ServerVersionNumber == 0 )
92
93
{
93
94
var parts = ServerVersion . Split ( '.' ) ;
94
- var version = int . Parse ( parts [ 0 ] ) * 1000 ;
95
+ var version = int . Parse ( parts [ 0 ] ) * 1000 ;
95
96
if ( parts . Length > 1 )
96
97
version += int . Parse ( parts [ 1 ] ) * 100 ;
97
98
if ( parts . Length > 2 )
@@ -100,7 +101,14 @@ private void Connect()
100
101
ServerVersionNumber = version ;
101
102
}
102
103
}
103
- catch { }
104
+ catch ( Exception )
105
+ {
106
+ //Twemproxy doesn't support the INFO command so automatically closes the socket
107
+ //Fallback to ServerVersionNumber=Unknown then try re-connecting
108
+ ServerVersionNumber = Unknown ;
109
+ Connect ( ) ;
110
+ return ;
111
+ }
104
112
105
113
var ipEndpoint = socket . LocalEndPoint as IPEndPoint ;
106
114
clientPort = ipEndpoint != null ? ipEndpoint . Port : - 1 ;
Original file line number Diff line number Diff line change 274
274
<Compile Include =" RedisPersistenceProviderTests.cs" />
275
275
<Compile Include =" ShippersExample.cs" />
276
276
<Compile Include =" TestData\PopulateTestData.cs" />
277
+ <Compile Include =" TwemproxyTests.cs" />
277
278
<Compile Include =" UserSessionRedisClientTests.cs" />
278
279
<Compile Include =" ValueTypeExamples.cs" />
279
280
<Compile Include =" QueueTests.cs" />
Original file line number Diff line number Diff line change
1
+ using NUnit . Framework ;
2
+ using ServiceStack . Text ;
3
+
4
+ namespace ServiceStack . Redis . Tests
5
+ {
6
+ [ TestFixture , Explicit ]
7
+ public class TwemproxyTests
8
+ {
9
+ [ Test ]
10
+ public void Can_connect_to_twemproxy ( )
11
+ {
12
+ var redis = new RedisClient ( "10.0.0.14" , 22121 ) {
13
+ //ServerVersionNumber = 2611
14
+ } ;
15
+ //var redis = new RedisClient("10.0.0.14");
16
+ redis . SetEntry ( "foo" , "bar" ) ;
17
+ var foo = redis . GetEntry ( "foo" ) ;
18
+
19
+ Assert . That ( foo , Is . EqualTo ( "bar" ) ) ;
20
+ }
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments