Skip to content
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

CONFIG and INFO command releated changes with Redis CE 8.0 #387

Merged
merged 2 commits into from
Jan 30, 2025
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: 2 additions & 0 deletions src/NRedisStack/Search/ISearchCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public interface ISearchCommands
/// <param name="option">is name of the configuration option, or '*' for all.</param>
/// <returns>An array reply of the configuration name and value.</returns>
/// <remarks><seealso href="https://redis.io/commands/ft.config-get"/></remarks>
[Obsolete("Starting from Redis 8.0, use db.ConfigGet instead")]
Dictionary<string, string> ConfigGet(string option);

/// <summary>
Expand All @@ -76,6 +77,7 @@ public interface ISearchCommands
/// <param name="value">is value of the configuration option.</param>
/// <returns><see langword="true"/> if executed correctly, error otherwise.</returns>
/// <remarks><seealso href="https://redis.io/commands/ft.config-set"/></remarks>
[Obsolete("Starting from Redis 8.0, use db.ConfigSet instead")]
bool ConfigSet(string option, string value);

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/NRedisStack/Search/ISearchCommandsAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public interface ISearchCommandsAsync
/// <param name="option">is name of the configuration option, or '*' for all.</param>
/// <returns>An array reply of the configuration name and value.</returns>
/// <remarks><seealso href="https://redis.io/commands/ft.config-get"/></remarks>
[Obsolete("Starting from Redis 8.0, use db.ConfigGetAsync instead")]
Task<Dictionary<string, string>> ConfigGetAsync(string option);

/// <summary>
Expand All @@ -75,6 +76,7 @@ public interface ISearchCommandsAsync
/// <param name="value">is value of the configuration option.</param>
/// <returns><see langword="true"/> if executed correctly, error otherwise.</returns>
/// <remarks><seealso href="https://redis.io/commands/ft.config-set"/></remarks>
[Obsolete("Starting from Redis 8.0, use db.ConfigSetAsync instead")]
Task<bool> ConfigSetAsync(string option, string value);

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/NRedisStack/Search/SearchCommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ public static SerializedCommand Alter(string index, Schema schema, bool skipInit
return new SerializedCommand(FT.ALTER, args);
}

[Obsolete("Starting from Redis 8.0, use db.ConfigGet instead")]
public static SerializedCommand ConfigGet(string option)
{
return new SerializedCommand(FT.CONFIG, "GET", option);
}

[Obsolete("Starting from Redis 8.0, use db.ConfigSet instead")]
public static SerializedCommand ConfigSet(string option, string value)
{
return new SerializedCommand(FT.CONFIG, "SET", option, value);
Expand Down
2 changes: 2 additions & 0 deletions src/NRedisStack/Search/SearchCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ public bool Alter(string index, Schema schema, bool skipInitialScan = false)
}

/// <inheritdoc/>
[Obsolete("Starting from Redis 8.0, use db.ConfigGet instead")]
public Dictionary<string, string> ConfigGet(string option)
{
return _db.Execute(SearchCommandBuilder.ConfigGet(option)).ToConfigDictionary();
}

/// <inheritdoc/>
[Obsolete("Starting from Redis 8.0, use db.ConfigSet instead")]
public bool ConfigSet(string option, string value)
{
return _db.Execute(SearchCommandBuilder.ConfigSet(option, value)).OKtoBoolean();
Expand Down
2 changes: 2 additions & 0 deletions src/NRedisStack/Search/SearchCommandsAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ public async Task<bool> AlterAsync(string index, Schema schema, bool skipInitial
}

/// <inheritdoc/>
[Obsolete("Starting from Redis 8.0, use db.ConfigGetAsync instead")]
public async Task<Dictionary<string, string>> ConfigGetAsync(string option)
{
return (await _db.ExecuteAsync(SearchCommandBuilder.ConfigGet(option))).ToConfigDictionary();
}

/// <inheritdoc/>
[Obsolete("Starting from Redis 8.0, use db.ConfigSetAsync instead")]
public async Task<bool> ConfigSetAsync(string option, string value)
{
return (await _db.ExecuteAsync(SearchCommandBuilder.ConfigSet(option, value))).OKtoBoolean();
Expand Down
113 changes: 113 additions & 0 deletions tests/NRedisStack.Tests/CommunityEditionUpdatesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using StackExchange.Redis;
using Xunit;

namespace NRedisStack.Tests;

public class CommunityEditionUpdatesTests : AbstractNRedisStackTest, IDisposable
{
public CommunityEditionUpdatesTests(EndpointsFixture endpointsFixture) : base(endpointsFixture) { }

private IServer getAnyPrimary(IConnectionMultiplexer muxer)
{
foreach (var endpoint in muxer.GetEndPoints())
{
var server = muxer.GetServer(endpoint);
if (!server.IsReplica) return server;
}
throw new InvalidOperationException("Requires a primary endpoint (found none)");
}

[SkipIfRedis(Comparison.LessThan, "7.9.0")]
[MemberData(nameof(EndpointsFixture.Env.AllEnvironments), MemberType = typeof(EndpointsFixture.Env))]
public void ConfigSearchSettings(string endpointId)
{
IDatabase db = GetCleanDatabase(endpointId);
IConnectionMultiplexer muxer = db.Multiplexer;
IServer server = getAnyPrimary(muxer);

server.ConfigSet("search-on-timeout", "fail");

Assert.Equal("fail", server.ConfigGet("search-on-timeout").First().Value);

server.ConfigSet("search-on-timeout", "return");

Assert.Single(server.ConfigGet("search-min-prefix"));

Assert.Single(server.ConfigGet("search-max-prefix-expansions"));

Assert.Single(server.ConfigGet("search-max-doctablesize"));

Assert.Single(server.ConfigGet("search-max-search-results"));

Assert.Single(server.ConfigGet("search-max-aggregate-results"));

Assert.Single(server.ConfigGet("search-friso-ini"));

Assert.Single(server.ConfigGet("search-default-dialect"));
}

[SkipIfRedis(Comparison.LessThan, "7.9.0")]
[MemberData(nameof(EndpointsFixture.Env.AllEnvironments), MemberType = typeof(EndpointsFixture.Env))]
public void ConfigTimeSeriesSettings(string endpointId)
{
IDatabase db = GetCleanDatabase(endpointId);
IConnectionMultiplexer muxer = db.Multiplexer;
IServer server = getAnyPrimary(muxer);

Assert.Single(server.ConfigGet("ts-compaction-policy"));

Assert.Single(server.ConfigGet("ts-retention-policy"));

Assert.Single(server.ConfigGet("ts-duplicate-policy"));

Assert.Single(server.ConfigGet("ts-encoding"));

Assert.Single(server.ConfigGet("ts-chunk-size-bytes"));

Assert.Single(server.ConfigGet("ts-ignore-max-time-diff"));

Assert.Single(server.ConfigGet("ts-ignore-max-val-diff"));
}

[SkipIfRedis(Comparison.LessThan, "7.9.0")]
[MemberData(nameof(EndpointsFixture.Env.AllEnvironments), MemberType = typeof(EndpointsFixture.Env))]
public void ConfigProbabilisticSettings(string endpointId)
{
IDatabase db = GetCleanDatabase(endpointId);
IConnectionMultiplexer muxer = db.Multiplexer;
IServer server = getAnyPrimary(muxer);

server.ConfigSet("bf-error-rate", "0.02");

Assert.Single(server.ConfigGet("bf-error-rate"));

Assert.Equal("0.02", server.ConfigGet("bf-error-rate").First().Value);

Assert.Single(server.ConfigGet("bf-initial-size"));

Assert.Single(server.ConfigGet("cf-max-expansions"));

Assert.Single(server.ConfigGet("bf-expansion-factor"));

Assert.Single(server.ConfigGet("cf-expansion-factor"));

Assert.Single(server.ConfigGet("cf-initial-size"));

Assert.Single(server.ConfigGet("cf-bucket-size"));

Assert.Single(server.ConfigGet("cf-max-iterations"));
}

[SkipIfRedis(Comparison.LessThan, "7.9.0")]
[MemberData(nameof(EndpointsFixture.Env.AllEnvironments), MemberType = typeof(EndpointsFixture.Env))]
public void InfoSearchSection(string endpointId)
{
IDatabase db = GetCleanDatabase(endpointId);
IConnectionMultiplexer muxer = db.Multiplexer;
IServer server = getAnyPrimary(muxer);

var searchInfo = server.Info("search");
CustomAssertions.GreaterThan(10, searchInfo.Length);
}

}
Loading