-
Notifications
You must be signed in to change notification settings - Fork 46
Support CLIENT SETINFO Command #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e496ec3
deprecated redisGraph
shacharPash ae8f952
supporting client SetInfo command
shacharPash d12bf7d
add tests
shacharPash f59afe0
check somthing
shacharPash f24cd97
check2
shacharPash 2b065b1
Async
shacharPash 072504e
try ConnectionMultiplexer.Connect("localhost");
shacharPash cdcb60a
Merge branch 'master' into Issue160/ClientSetInfo
shacharPash df78947
new format
shacharPash b61a324
Merge branch 'master' into Issue160/ClientSetInfo
shacharPash 522bb91
fix core tests
shacharPash 0ae22fb
try change to IDatabase instead of IDatabaseAsync
shacharPash c79fe40
add bool _setinfo to Auxiliary
shacharPash 111e734
comment CoreTests
shacharPash f6cac53
fix Aux
shacharPash 3409bfe
change test
shacharPash 62f27cf
fix tests
shacharPash 1122e69
not using pipeline
shacharPash 8739251
move _setInfo = false;
shacharPash 36749d7
delete unused key
shacharPash 3822d06
if redis version less than 7.1.242 dont sent SETINFO
shacharPash fce926f
add sleep
shacharPash 08b89c6
no sleep
shacharPash 0e4876f
Merge branch 'master' into Issue160/ClientSetInfo
shacharPash 5a0dd0b
Merge branch 'master' into Issue160/ClientSetInfo
shacharPash 96dc3b2
Merge branch 'master' into Issue160/ClientSetInfo
shacharPash f72b28d
try setinfo to true in each test
shacharPash 1c4dd72
reset info defaults in each test
shacharPash 1bca657
skip cluster + send commands in pipeline
shacharPash ba79c14
delete comments
shacharPash 3f548d5
add null test
shacharPash 68b6f5f
compare and of strings in null test
shacharPash 28bc9e0
fixes
shacharPash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using NRedisStack.RedisStackCommands; | ||
using NRedisStack.Core.Literals; | ||
using NRedisStack.Core; | ||
|
||
namespace NRedisStack | ||
{ | ||
|
||
public static class CoreCommandBuilder | ||
{ | ||
public static SerializedCommand ClientSetInfo(SetInfoAttr attr, string value) | ||
{ | ||
string attrValue = attr switch | ||
{ | ||
SetInfoAttr.LibraryName => CoreArgs.lib_name, | ||
SetInfoAttr.LibraryVersion => CoreArgs.lib_ver, | ||
_ => throw new System.NotImplementedException(), | ||
}; | ||
|
||
return new SerializedCommand(RedisCoreCommands.CLIENT, RedisCoreCommands.SETINFO, attrValue, value); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using NRedisStack.Core; | ||
using StackExchange.Redis; | ||
namespace NRedisStack | ||
{ | ||
|
||
public static class CoreCommands | ||
{ | ||
/// <summary> | ||
/// Sets information specific to the client or connection. | ||
/// </summary> | ||
/// <param name="attr">which attribute to set</param> | ||
/// <param name="value">the attribute value</param> | ||
/// <returns><see langword="true"/> if the attribute name was successfully set, Error otherwise.</returns> | ||
/// <remarks><seealso href="https://redis.io/commands/client-setinfo/"/></remarks> | ||
public static bool ClientSetInfo(this IDatabase db, SetInfoAttr attr, string value) | ||
{ | ||
return db.Execute(CoreCommandBuilder.ClientSetInfo(attr, value)).OKtoBoolean(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using NRedisStack.Core; | ||
using StackExchange.Redis; | ||
namespace NRedisStack | ||
{ | ||
|
||
public static class CoreCommandsAsync //: ICoreCommandsAsync | ||
{ | ||
/// <summary> | ||
/// Sets information specific to the client or connection. | ||
/// </summary> | ||
/// <param name="attr">which attribute to set</param> | ||
/// <param name="value">the attribute value</param> | ||
/// <returns><see langword="true"/> if the attribute name was successfully set, Error otherwise.</returns> | ||
/// <remarks><seealso href="https://redis.io/commands/client-setinfo/"/></remarks> | ||
public static async Task<bool> ClientSetInfoAsync(this IDatabaseAsync db, SetInfoAttr attr, string value) | ||
{ | ||
return (await db.ExecuteAsync(CoreCommandBuilder.ClientSetInfo(attr, value))).OKtoBoolean(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace NRedisStack.Core; | ||
public enum SetInfoAttr | ||
{ | ||
/// <summary> | ||
/// meant to hold the name of the client library that's in use. | ||
/// </summary> | ||
LibraryName, | ||
/// <summary> | ||
/// meant to hold the client library's version. | ||
/// </summary> | ||
LibraryVersion | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace NRedisStack.Core.Literals | ||
{ | ||
internal class CoreArgs | ||
{ | ||
public const string lib_name = "LIB-NAME"; | ||
public const string lib_ver = "LIB-VER"; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace NRedisStack.Core.Literals | ||
{ | ||
/// <summary> | ||
/// Redis Core command literals | ||
/// </summary> | ||
internal class RedisCoreCommands | ||
{ | ||
public const string CLIENT = "CLIENT"; | ||
public const string SETINFO = "SETINFO"; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
using Xunit; | ||
using NRedisStack.Core; | ||
using NRedisStack; | ||
using static NRedisStack.Auxiliary; | ||
using StackExchange.Redis; | ||
using System.Xml.Linq; | ||
using System.Reflection; | ||
using NRedisStack.RedisStackCommands; | ||
|
||
|
||
namespace NRedisStack.Tests.Core; | ||
|
||
public class CoreTests : AbstractNRedisStackTest, IDisposable | ||
{ | ||
public CoreTests(RedisFixture redisFixture) : base(redisFixture) { } | ||
|
||
|
||
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] | ||
public void TestSimpleSetInfo() | ||
{ | ||
var redis = ConnectionMultiplexer.Connect("localhost"); | ||
var db = redis.GetDatabase(); | ||
db.Execute("FLUSHALL"); | ||
|
||
db.ClientSetInfo(SetInfoAttr.LibraryName, "TestLibraryName"); | ||
db.ClientSetInfo(SetInfoAttr.LibraryVersion, "1.2.3"); | ||
|
||
var info = db.Execute("CLIENT", "INFO").ToString(); | ||
Assert.EndsWith($"lib-name=TestLibraryName lib-ver=1.2.3\n", info); | ||
} | ||
|
||
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] | ||
public async Task TestSimpleSetInfoAsync() | ||
{ | ||
var redis = ConnectionMultiplexer.Connect("localhost"); | ||
var db = redis.GetDatabase(); | ||
db.Execute("FLUSHALL"); | ||
|
||
await db.ClientSetInfoAsync(SetInfoAttr.LibraryName, "TestLibraryName"); | ||
await db.ClientSetInfoAsync(SetInfoAttr.LibraryVersion, "1.2.3"); | ||
|
||
var info = db.Execute("CLIENT", "INFO").ToString(); | ||
Assert.EndsWith($"lib-name=TestLibraryName lib-ver=1.2.3\n", info); | ||
} | ||
|
||
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] | ||
public void TestSetInfoDefaultValue() | ||
{ | ||
ResetInfoDefaults(); // demonstrate first connection | ||
var redis = ConnectionMultiplexer.Connect("localhost"); | ||
var db = redis.GetDatabase(); | ||
db.Execute("FLUSHALL"); | ||
|
||
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. | ||
|
||
var info = db.Execute("CLIENT", "INFO").ToString(); | ||
Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); | ||
} | ||
|
||
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] | ||
public async Task TestSetInfoDefaultValueAsync() | ||
{ | ||
ResetInfoDefaults(); // demonstrate first connection | ||
var redis = ConnectionMultiplexer.Connect("localhost"); | ||
var db = redis.GetDatabase(); | ||
db.Execute("FLUSHALL"); | ||
|
||
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. | ||
|
||
var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); | ||
Assert.EndsWith($"lib-name=NRedisStack;.NET-{Environment.Version} lib-ver={GetNRedisStackVersion()}\n", info); | ||
} | ||
|
||
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] | ||
public void TestSetInfoWithValue() | ||
{ | ||
ResetInfoDefaults(); // demonstrate first connection | ||
var redis = ConnectionMultiplexer.Connect("localhost"); | ||
var db = redis.GetDatabase("MyLibraryName;v1.0.0"); | ||
db.Execute("FLUSHALL"); | ||
|
||
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. | ||
|
||
var info = db.Execute("CLIENT", "INFO").ToString(); | ||
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); | ||
} | ||
|
||
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] | ||
public async Task TestSetInfoWithValueAsync() | ||
{ | ||
ResetInfoDefaults(); // demonstrate first connection | ||
var redis = ConnectionMultiplexer.Connect("localhost"); | ||
var db = redis.GetDatabase("MyLibraryName;v1.0.0"); | ||
db.Execute("FLUSHALL"); | ||
|
||
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. | ||
|
||
var info = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); | ||
Assert.EndsWith($"NRedisStack(MyLibraryName;v1.0.0);.NET-{Environment.Version}) lib-ver={GetNRedisStackVersion()}\n", info); | ||
} | ||
|
||
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] | ||
public void TestSetInfoNull() | ||
{ | ||
ResetInfoDefaults(); // demonstrate first connection | ||
var redis = ConnectionMultiplexer.Connect("localhost"); | ||
var db = redis.GetDatabase(null); | ||
|
||
db.Execute("FLUSHALL"); | ||
var infoBefore = db.Execute("CLIENT", "INFO").ToString(); | ||
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. | ||
|
||
var infoAfter = db.Execute("CLIENT", "INFO").ToString(); | ||
// Find the indices of "lib-name=" in the strings | ||
int infoAfterLibNameIndex = infoAfter!.IndexOf("lib-name="); | ||
int infoBeforeLibNameIndex = infoBefore!.IndexOf("lib-name="); | ||
|
||
// Extract the sub-strings starting from "lib-name=" | ||
string infoAfterLibNameToEnd = infoAfter.Substring(infoAfterLibNameIndex); | ||
string infoBeforeLibNameToEnd = infoBefore.Substring(infoBeforeLibNameIndex); | ||
|
||
// Assert that the extracted sub-strings are equal | ||
Assert.Equal(infoAfterLibNameToEnd, infoBeforeLibNameToEnd); | ||
} | ||
|
||
[SkipIfRedis(Is.OSSCluster, Comparison.LessThan, "7.1.242")] | ||
public async Task TestSetInfoNullAsync() | ||
{ | ||
ResetInfoDefaults(); // demonstrate first connection | ||
var redis = ConnectionMultiplexer.Connect("localhost"); | ||
var db = redis.GetDatabase(null); | ||
|
||
db.Execute("FLUSHALL"); | ||
var infoBefore = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); | ||
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. | ||
|
||
var infoAfter = (await db.ExecuteAsync("CLIENT", "INFO")).ToString(); | ||
// Find the indices of "lib-name=" in the strings | ||
int infoAfterLibNameIndex = infoAfter!.IndexOf("lib-name="); | ||
int infoBeforeLibNameIndex = infoBefore!.IndexOf("lib-name="); | ||
|
||
// Extract the sub-strings starting from "lib-name=" | ||
string infoAfterLibNameToEnd = infoAfter.Substring(infoAfterLibNameIndex); | ||
string infoBeforeLibNameToEnd = infoBefore.Substring(infoBeforeLibNameIndex); | ||
|
||
// Assert that the extracted sub-strings are equal | ||
Assert.Equal(infoAfterLibNameToEnd, infoBeforeLibNameToEnd); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.