Skip to content

Commit

Permalink
Use machine name as default client name; tests for RedisLabs SSL; rem…
Browse files Browse the repository at this point in the history
…ove "beta" copy from readme
  • Loading branch information
mgravell committed Apr 16, 2014
1 parent b823aed commit 028ab58
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 7 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ StackExchange.Redis is a high performance general purpose redis client for .NET
and is the client developed-by (and used-by) [Stack Exchange](http://stackexchange.com/) for busy sites like [Stack Overflow](http://stackoverflow.com/). For the full reasons
why this library was created (i.e. "What about BookSleeve?") [please see here](http://marcgravell.blogspot.com/2014/03/so-i-went-and-wrote-another-redis-client.html).

Note: this release should be considered "beta": the API may be subject to minor changes.

Features
--

Expand Down
52 changes: 52 additions & 0 deletions StackExchange.Redis.Tests/SSL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Net;
using NUnit.Framework;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

namespace StackExchange.Redis.Tests
{
Expand Down Expand Up @@ -119,5 +121,55 @@ private static void TestConcurrent(IDatabase db, RedisKey key, int SyncLoop, int
(long)((SyncLoop * Threads) / time.TotalSeconds),
value);
}


[Test]
public void RedisLabsSSL()
{
const string path = @"d:\RedisLabsSslHost.txt";
const string pfxPath = @"d:\RedisLabsUser.pfx";

if (!File.Exists(path)) Assert.Inconclusive();
string hostAndPort = File.ReadAllText(path);
int timeout = 5000;
if (Debugger.IsAttached) timeout *= 100;
var options = new ConfigurationOptions
{
EndPoints = { hostAndPort },
ConnectTimeout = timeout,
AllowAdmin = true,
CommandMap = CommandMap.Create(new HashSet<string> {
"subscribe", "unsubscribe", "cluster"
}, false)
};
if (!Directory.Exists(Me())) Directory.CreateDirectory(Me());
#if LOGOUTPUT
ConnectionMultiplexer.EchoPath = Me();
#endif
options.UseSsl = true;
options.CertificateSelection += delegate {
return new X509Certificate2(pfxPath, "pass");
};
RedisKey key = Me();
using(var conn = ConnectionMultiplexer.Connect(options))
{
var db = conn.GetDatabase();
db.KeyDelete(key);
string s = db.StringGet(key);
Assert.IsNull(s);
db.StringSet(key, "abc");
s = db.StringGet(key);
Assert.AreEqual("abc", s);

var latency = db.Ping();
Console.WriteLine("RedisLabs latency: {0:###,##0.##}ms", latency.TotalMilliseconds);

using (var file = File.Create("RedisLabs.zip"))
{
conn.ExportConfiguration(file);
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ partial class ConnectionMultiplexer
partial void OnCreateReaderWriter(ConfigurationOptions configuration)
{
this.ownsSocketManager = configuration.SocketManager == null;
this.socketManager = configuration.SocketManager ?? new SocketManager(configuration.ClientName);
this.socketManager = configuration.SocketManager ?? new SocketManager(ClientName);
}

partial void OnCloseReaderWriter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public ServerCounters GetCounters()
}

/// <summary>
/// Gets or sets a client-name that will be used on all new connections
/// Gets the client-name that will be used on all new connections
/// </summary>
public string ClientName { get { return configuration.ClientName; } }
public string ClientName { get { return configuration.ClientName ?? Environment.MachineName; } }

/// <summary>
/// Gets the configuration of the connection
Expand Down
2 changes: 1 addition & 1 deletion StackExchange.Redis/StackExchange/Redis/DebuggingAids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;

using System.Text.RegularExpressions;
namespace StackExchange.Redis
{
#if DEBUG
Expand Down
8 changes: 7 additions & 1 deletion StackExchange.Redis/StackExchange/Redis/LoggingTextStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
namespace StackExchange.Redis
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;

namespace StackExchange.Redis
{
#if LOGOUTPUT
sealed class LoggingTextStream : Stream
Expand Down

0 comments on commit 028ab58

Please sign in to comment.