Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageProjectUrl>https://github.com/StackExchange/StackExchange.Redis/</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>

<LangVersion>9.0</LangVersion>
<LangVersion>10.0</LangVersion>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/StackExchange/StackExchange.Redis/</RepositoryUrl>

Expand Down
1 change: 1 addition & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Fixes a race in subscribing immediately before a publish
- Fixes subscription routing on clusters (spreading instead of choosing 1 node)
- More correctly reconnects subscriptions on connection failures, including to other endpoints
- Adds "(vX.X.X)" version suffix to the default client ID so server-side `CLIENT LIST` can more easily see what's connected (#1985 via NickCraver)

## 2.2.88

Expand Down
7 changes: 5 additions & 2 deletions src/StackExchange.Redis/ConnectionMultiplexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ public ServerCounters GetCounters()

private static string defaultClientName;

/// <summary>
/// Gets the client name for a connection, with the library version appended.
/// </summary>
private static string GetDefaultClientName()
{
return defaultClientName ??= TryGetAzureRoleInstanceIdNoThrow()
return defaultClientName ??= (TryGetAzureRoleInstanceIdNoThrow()
?? Environment.MachineName
?? Environment.GetEnvironmentVariable("ComputerName")
?? "StackExchange.Redis";
?? "StackExchange.Redis") + "(v" + Utils.GetLibVersion() + ")";
}

/// <summary>
Expand Down
13 changes: 1 addition & 12 deletions src/StackExchange.Redis/ExceptionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,6 @@ internal static Exception NoCursor(RedisCommand command)
return new RedisCommandException("Command cannot be used with a cursor: " + s);
}

private static string _libVersion;
internal static string GetLibVersion()
{
if (_libVersion == null)
{
var assembly = typeof(ConnectionMultiplexer).Assembly;
_libVersion = ((AssemblyFileVersionAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyFileVersionAttribute)))?.Version
?? assembly.GetName().Version.ToString();
}
return _libVersion;
}
private static void Add(List<Tuple<string, string>> data, StringBuilder sb, string lk, string sk, string v)
{
if (v != null)
Expand Down Expand Up @@ -365,7 +354,7 @@ ServerEndPoint server
Add(data, sb, "Local-CPU", "Local-CPU", PerfCounterHelper.GetSystemCpuPercent());
}

Add(data, sb, "Version", "v", GetLibVersion());
Add(data, sb, "Version", "v", Utils.GetLibVersion());
}

private static void AddExceptionDetail(Exception exception, Message message, ServerEndPoint server, string label)
Expand Down
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/PhysicalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void add(string lk, string sk, string v)
}
}

add("Version", "v", ExceptionFactory.GetLibVersion());
add("Version", "v", Utils.GetLibVersion());

outerException = new RedisConnectionException(failureType, exMessage.ToString(), innerException);

Expand Down
19 changes: 19 additions & 0 deletions src/StackExchange.Redis/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Reflection;

namespace StackExchange.Redis;

internal static class Utils
{
private static string _libVersion;
internal static string GetLibVersion()
{
if (_libVersion == null)
{
var assembly = typeof(ConnectionMultiplexer).Assembly;
_libVersion = ((AssemblyFileVersionAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyFileVersionAttribute)))?.Version
?? assembly.GetName().Version.ToString();
}
return _libVersion;
}
}
4 changes: 2 additions & 2 deletions tests/StackExchange.Redis.Tests/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ public void DefaultClientName()
{
using (var muxer = Create(allowAdmin: true, caller: null)) // force default naming to kick in
{
Assert.Equal(Environment.MachineName, muxer.ClientName);
Assert.Equal($"{Environment.MachineName}(v{Utils.GetLibVersion()})", muxer.ClientName);
var conn = muxer.GetDatabase();
conn.Ping();

var name = (string)GetAnyMaster(muxer).Execute("CLIENT", "GETNAME");
Assert.Equal(Environment.MachineName, name);
Assert.Equal($"{Environment.MachineName}(v{Utils.GetLibVersion()})", name);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/ExceptionFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void NullLastException()
[Fact]
public void CanGetVersion()
{
var libVer = ExceptionFactory.GetLibVersion();
var libVer = Utils.GetLibVersion();
Assert.Matches(@"2\.[0-9]+\.[0-9]+(\.[0-9]+)?", libVer);
}

Expand Down