This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
tests/ServiceStack.Redis.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public partial class RedisNativeClient
2626 {
2727 private static Timer UsageTimer ;
2828 private static int __requestsPerHour = 0 ;
29+ private const int Unknown = - 1 ;
2930 public int ServerVersionNumber { get ; set ; }
3031
3132 public static void DisposeTimers ( )
@@ -91,7 +92,7 @@ private void Connect()
9192 if ( ServerVersionNumber == 0 )
9293 {
9394 var parts = ServerVersion . Split ( '.' ) ;
94- var version = int . Parse ( parts [ 0 ] ) * 1000 ;
95+ var version = int . Parse ( parts [ 0 ] ) * 1000 ;
9596 if ( parts . Length > 1 )
9697 version += int . Parse ( parts [ 1 ] ) * 100 ;
9798 if ( parts . Length > 2 )
@@ -100,7 +101,14 @@ private void Connect()
100101 ServerVersionNumber = version ;
101102 }
102103 }
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+ }
104112
105113 var ipEndpoint = socket . LocalEndPoint as IPEndPoint ;
106114 clientPort = ipEndpoint != null ? ipEndpoint . Port : - 1 ;
Original file line number Diff line number Diff line change 274274 <Compile Include =" RedisPersistenceProviderTests.cs" />
275275 <Compile Include =" ShippersExample.cs" />
276276 <Compile Include =" TestData\PopulateTestData.cs" />
277+ <Compile Include =" TwemproxyTests.cs" />
277278 <Compile Include =" UserSessionRedisClientTests.cs" />
278279 <Compile Include =" ValueTypeExamples.cs" />
279280 <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