Skip to content

Commit b05d08b

Browse files
shacharPashchayim
andauthoredDec 18, 2023
Fix SETINFO Format (#203)
* change setinfo process * change version to 7, 1, 242 * fix setinfo format * delete comment --------- Co-authored-by: Chayim <[email protected]>
1 parent 92e3d82 commit b05d08b

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed
 

‎src/NRedisStack/Auxiliary.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace NRedisStack
66
{
77
public static class Auxiliary
88
{
9-
private static string? _libraryName = $"NRedisStack;.NET-{Environment.Version}";
9+
private static string? _libraryName = $"NRedisStack(.NET_v{Environment.Version})";
1010
private static bool _setInfo = true;
1111
public static void ResetInfoDefaults()
1212
{
1313
_setInfo = true;
14-
_libraryName = $"NRedisStack;.NET-{Environment.Version}";
14+
_libraryName = $"NRedisStack(.NET_v{Environment.Version})";
1515
}
1616
public static List<object> MergeArgs(RedisKey key, params RedisValue[] items)
1717
{
@@ -34,8 +34,6 @@ public static object[] AssembleNonNullArguments(params object?[] arguments)
3434
return args.ToArray();
3535
}
3636

37-
// public static IDatabase GetDatabase(this ConnectionMultiplexer redis) => redis.GetDatabase("", "");
38-
3937
// TODO: add all the signatures of GetDatabase
4038
public static IDatabase GetDatabase(this ConnectionMultiplexer redis,
4139
string? LibraryName)
@@ -45,7 +43,7 @@ public static IDatabase GetDatabase(this ConnectionMultiplexer redis,
4543
_setInfo = false;
4644

4745
else // the user set his own the library name
48-
_libraryName = $"NRedisStack({LibraryName});.NET-{Environment.Version})";
46+
_libraryName = $"NRedisStack({LibraryName};.NET_v{Environment.Version})";
4947

5048
return _db;
5149
}
@@ -61,8 +59,7 @@ private static void SetInfoInPipeline(this IDatabase db)
6159

6260
public static RedisResult Execute(this IDatabase db, SerializedCommand command)
6361
{
64-
var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242));
65-
if (_setInfo && compareVersions >= 0)
62+
if (_setInfo)
6663
{
6764
_setInfo = false;
6865
db.SetInfoInPipeline();
@@ -72,8 +69,7 @@ public static RedisResult Execute(this IDatabase db, SerializedCommand command)
7269

7370
public async static Task<RedisResult> ExecuteAsync(this IDatabaseAsync db, SerializedCommand command)
7471
{
75-
var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242));
76-
if (_setInfo && compareVersions >= 0)
72+
if (_setInfo)
7773
{
7874
_setInfo = false;
7975
((IDatabase)db).SetInfoInPipeline();
@@ -135,4 +131,4 @@ public static string GetNRedisStackVersion()
135131
return $"{version.Major}.{version.Minor}.{version.Build}";
136132
}
137133
}
138-
}
134+
}

‎src/NRedisStack/CoreCommands/CoreCommands.cs

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public static class CoreCommands
1414
/// <remarks><seealso href="https://redis.io/commands/client-setinfo/"/></remarks>
1515
public static bool ClientSetInfo(this IDatabase db, SetInfoAttr attr, string value)
1616
{
17+
var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242));
18+
if (compareVersions < 0) // the server does not support the CLIENT SETNAME command
19+
return false;
1720
return db.Execute(CoreCommandBuilder.ClientSetInfo(attr, value)).OKtoBoolean();
1821
}
1922
}

‎src/NRedisStack/CoreCommands/CoreCommandsAsync.cs

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public static class CoreCommandsAsync //: ICoreCommandsAsync
1414
/// <remarks><seealso href="https://redis.io/commands/client-setinfo/"/></remarks>
1515
public static async Task<bool> ClientSetInfoAsync(this IDatabaseAsync db, SetInfoAttr attr, string value)
1616
{
17+
var compareVersions = db.Multiplexer.GetServer(db.Multiplexer.GetEndPoints()[0]).Version.CompareTo(new Version(7, 1, 242));
18+
if (compareVersions < 0) // the server does not support the CLIENT SETNAME command
19+
{
20+
return false;
21+
}
1722
return (await db.ExecuteAsync(CoreCommandBuilder.ClientSetInfo(attr, value))).OKtoBoolean();
1823
}
1924
}

‎tests/NRedisStack.Tests/Core Commands/CoreTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void TestSetInfoDefaultValue()
5454
db.Execute(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
5555

5656
var info = db.Execute("CLIENT", "INFO").ToString();
57-
Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info);
57+
Assert.EndsWith($"lib-name=NRedisStack(.NET_v{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
5858
}
5959

6060
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
@@ -68,7 +68,7 @@ public async Task TestSetInfoDefaultValueAsync()
6868
await db.ExecuteAsync(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
6969

7070
var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString();
71-
Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info);
71+
Assert.EndsWith($"lib-name=NRedisStack(.NET_v{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
7272
}
7373

7474
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
@@ -82,7 +82,7 @@ public void TestSetInfoWithValue()
8282
db.Execute(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
8383

8484
var info = db.Execute("CLIENT", "INFO").ToString();
85-
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
85+
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0;.NET_v{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
8686
}
8787

8888
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]
@@ -96,7 +96,7 @@ public async Task TestSetInfoWithValueAsync()
9696
await db.ExecuteAsync(new SerializedCommand("PING")); // only the extension method of Execute (which is used for all the commands of Redis Stack) will set the library name and version.
9797

9898
var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString();
99-
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
99+
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0;.NET_v{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info);
100100
}
101101

102102
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")]

0 commit comments

Comments
 (0)
Please sign in to comment.