Skip to content

Commit 64bed3f

Browse files
authored
Handle FT.PROFILE response (impacted with Coordinator) processing with "ProfilingInformation" (#373)
* handle ft.profile response processing with "ProfilingInformation" * fix formatting * make old methods obsolete
1 parent 744814c commit 64bed3f

File tree

8 files changed

+272
-41
lines changed

8 files changed

+272
-41
lines changed

src/NRedisStack/ResponseParser.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,15 @@ public static Tuple<SearchResult, Dictionary<string, RedisResult>> ToProfileSear
694694
return new Tuple<SearchResult, Dictionary<string, RedisResult>>(searchResult, profile);
695695
}
696696

697+
public static Tuple<SearchResult, ProfilingInformation> ParseProfileSearchResult(this RedisResult result, Query q)
698+
{
699+
var results = (RedisResult[])result!;
700+
701+
var searchResult = results[0].ToSearchResult(q);
702+
var profile = new ProfilingInformation(results[1]);
703+
return new Tuple<SearchResult, ProfilingInformation>(searchResult, profile);
704+
}
705+
697706
public static SearchResult ToSearchResult(this RedisResult result, Query q)
698707
{
699708
return new SearchResult((RedisResult[])result!, !q.NoContent, q.WithScores, q.WithPayloads/*, q.ExplainScore*/);
@@ -707,6 +716,14 @@ public static Tuple<AggregationResult, Dictionary<string, RedisResult>> ToProfil
707716
return new Tuple<AggregationResult, Dictionary<string, RedisResult>>(aggregateResult, profile);
708717
}
709718

719+
public static Tuple<AggregationResult, ProfilingInformation> ParseProfileAggregateResult(this RedisResult result, AggregationRequest q)
720+
{
721+
var results = (RedisResult[])result!;
722+
var aggregateResult = results[0].ToAggregationResult(q);
723+
var profile = new ProfilingInformation(results[1]);
724+
return new Tuple<AggregationResult, ProfilingInformation>(aggregateResult, profile);
725+
}
726+
710727
public static AggregationResult ToAggregationResult(this RedisResult result, AggregationRequest query)
711728
{
712729
if (query.IsWithCursor())

src/NRedisStack/Search/ISearchCommands.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,37 @@ public interface ISearchCommands
177177
/// <param name="q">The query string.</param>
178178
/// <param name="limited">Removes details of reader iterator.</param>
179179
/// <returns></returns>
180+
[Obsolete("Consider using ProfileOnSearch with Redis CE 8.0 and later")]
180181
Tuple<SearchResult, Dictionary<string, RedisResult>> ProfileSearch(string indexName, Query q, bool limited = false);
181182

183+
/// <summary>
184+
/// Apply FT.SEARCH command to collect performance details.
185+
/// </summary>
186+
/// <param name="indexName">The index name, created using FT.CREATE.</param>
187+
/// <param name="q">The query string.</param>
188+
/// <param name="limited">Removes details of reader iterator.</param>
189+
/// <returns></returns>
190+
Tuple<SearchResult, ProfilingInformation> ProfileOnSearch(string indexName, Query q, bool limited = false);
191+
182192
/// <summary>
183193
/// Apply FT.AGGREGATE command to collect performance details.
184194
/// </summary>
185195
/// <param name="indexName">The index name, created using FT.CREATE.</param>
186196
/// <param name="query">The query string.</param>
187197
/// <param name="limited">Removes details of reader iterator.</param>
188198
/// <returns></returns>
199+
[Obsolete("Consider using ProfileOnAggregate with Redis CE 8.0 and later")]
189200
Tuple<AggregationResult, Dictionary<string, RedisResult>> ProfileAggregate(string indexName, AggregationRequest query, bool limited = false);
190201

202+
/// <summary>
203+
/// Apply FT.AGGREGATE command to collect performance details.
204+
/// </summary>
205+
/// <param name="indexName">The index name, created using FT.CREATE.</param>
206+
/// <param name="query">The query string.</param>
207+
/// <param name="limited">Removes details of reader iterator.</param>
208+
/// <returns></returns>
209+
Tuple<AggregationResult, ProfilingInformation> ProfileOnAggregate(string indexName, AggregationRequest query, bool limited = false);
210+
191211
/// <summary>
192212
/// Search the index
193213
/// </summary>

src/NRedisStack/Search/ISearchCommandsAsync.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,24 @@ public interface ISearchCommandsAsync
169169
/// <remarks><seealso href="https://redis.io/commands/ft.info"/></remarks>
170170
Task<InfoResult> InfoAsync(RedisValue index);
171171

172-
173172
/// <summary>
174173
/// Apply FT.SEARCH command to collect performance details.
175174
/// </summary>
176175
/// <param name="indexName">The index name, created using FT.CREATE.</param>
177176
/// <param name="q">The query string.</param>
178177
/// <param name="limited">Removes details of reader iterator.</param>
179178
/// <returns></returns>
179+
[Obsolete("Consider using ProfileOnSearchAsync with Redis CE 8.0 and later")]
180180
Task<Tuple<SearchResult, Dictionary<string, RedisResult>>> ProfileSearchAsync(string indexName, Query q, bool limited = false);
181181

182+
/// <summary>
183+
/// Apply FT.SEARCH command to collect performance details.
184+
/// </summary>
185+
/// <param name="indexName">The index name, created using FT.CREATE.</param>
186+
/// <param name="q">The query string.</param>
187+
/// <param name="limited">Removes details of reader iterator.</param>
188+
/// <returns></returns>
189+
Task<Tuple<SearchResult, ProfilingInformation>> ProfileOnSearchAsync(string indexName, Query q, bool limited = false);
182190

183191
/// <summary>
184192
/// Apply FT.AGGREGATE command to collect performance details.
@@ -187,8 +195,18 @@ public interface ISearchCommandsAsync
187195
/// <param name="query">The query string.</param>
188196
/// <param name="limited">Removes details of reader iterator.</param>
189197
/// <returns></returns>
198+
[Obsolete("Consider using ProfileOnAggregateAsync with Redis CE 8.0 and later")]
190199
Task<Tuple<AggregationResult, Dictionary<string, RedisResult>>> ProfileAggregateAsync(string indexName, AggregationRequest query, bool limited = false);
191200

201+
/// <summary>
202+
/// Apply FT.AGGREGATE command to collect performance details.
203+
/// </summary>
204+
/// <param name="indexName">The index name, created using FT.CREATE.</param>
205+
/// <param name="query">The query string.</param>
206+
/// <param name="limited">Removes details of reader iterator.</param>
207+
/// <returns></returns>
208+
Task<Tuple<AggregationResult, ProfilingInformation>> ProfileOnAggregateAsync(string indexName, AggregationRequest query, bool limited = false);
209+
192210
/// <summary>
193211
/// Search the index
194212
/// </summary>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using StackExchange.Redis;
2+
3+
namespace NRedisStack.Search
4+
{
5+
6+
public class ProfilingInformation
7+
{
8+
public RedisResult Info { get; private set; }
9+
public ProfilingInformation(RedisResult info)
10+
{
11+
this.Info = info;
12+
}
13+
14+
}
15+
}

src/NRedisStack/Search/SearchCommands.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,37 @@ public InfoResult Info(RedisValue index) =>
131131
new InfoResult(_db.Execute(SearchCommandBuilder.Info(index)));
132132

133133
/// <inheritdoc/>
134+
[Obsolete("Consider using ProfileOnSearch with Redis CE 8.0 and later")]
134135
public Tuple<SearchResult, Dictionary<string, RedisResult>> ProfileSearch(string indexName, Query q, bool limited = false)
135136
{
136137
return _db.Execute(SearchCommandBuilder.ProfileSearch(indexName, q, limited))
137-
.ToProfileSearchResult(q);
138+
.ToProfileSearchResult(q);
138139
}
140+
139141
/// <inheritdoc/>
142+
public Tuple<SearchResult, ProfilingInformation> ProfileOnSearch(string indexName, Query q, bool limited = false)
143+
{
144+
return _db.Execute(SearchCommandBuilder.ProfileSearch(indexName, q, limited))
145+
.ParseProfileSearchResult(q);
146+
}
147+
148+
/// <inheritdoc/>
149+
[Obsolete("Consider using ProfileOnAggregate with Redis CE 8.0 and later")]
140150
public Tuple<AggregationResult, Dictionary<string, RedisResult>> ProfileAggregate(string indexName, AggregationRequest query, bool limited = false)
141151
{
142152
setDefaultDialectIfUnset(query);
143153
return _db.Execute(SearchCommandBuilder.ProfileAggregate(indexName, query, limited))
144154
.ToProfileAggregateResult(query);
145155
}
156+
157+
/// <inheritdoc/>
158+
public Tuple<AggregationResult, ProfilingInformation> ProfileOnAggregate(string indexName, AggregationRequest query, bool limited = false)
159+
{
160+
setDefaultDialectIfUnset(query);
161+
return _db.Execute(SearchCommandBuilder.ProfileAggregate(indexName, query, limited))
162+
.ParseProfileAggregateResult(query);
163+
}
164+
146165
/// <inheritdoc/>
147166
public SearchResult Search(string indexName, Query q)
148167
{

src/NRedisStack/Search/SearchCommandsAsync.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,32 @@ public async Task<InfoResult> InfoAsync(RedisValue index) =>
162162
new InfoResult(await _db.ExecuteAsync(SearchCommandBuilder.Info(index)));
163163

164164
/// <inheritdoc/>
165+
[Obsolete("Consider using ProfileOnSearchAsync with Redis CE 8.0 and later")]
165166
public async Task<Tuple<SearchResult, Dictionary<string, RedisResult>>> ProfileSearchAsync(string indexName, Query q, bool limited = false)
166167
{
167168
return (await _db.ExecuteAsync(SearchCommandBuilder.ProfileSearch(indexName, q, limited)))
168169
.ToProfileSearchResult(q);
169170
}
171+
172+
/// <inheritdoc/>
173+
public async Task<Tuple<SearchResult, ProfilingInformation>> ProfileOnSearchAsync(string indexName, Query q, bool limited = false)
174+
{
175+
return (await _db.ExecuteAsync(SearchCommandBuilder.ProfileSearch(indexName, q, limited)))
176+
.ParseProfileSearchResult(q);
177+
}
170178
/// <inheritdoc/>
179+
[Obsolete("Consider using ProfileOnSearchAsync with Redis CE 8.0 and later")]
171180
public async Task<Tuple<AggregationResult, Dictionary<string, RedisResult>>> ProfileAggregateAsync(string indexName, AggregationRequest query, bool limited = false)
172181
{
173182
return (await _db.ExecuteAsync(SearchCommandBuilder.ProfileAggregate(indexName, query, limited)))
174183
.ToProfileAggregateResult(query);
175184
}
185+
/// <inheritdoc/>
186+
public async Task<Tuple<AggregationResult, ProfilingInformation>> ProfileOnAggregateAsync(string indexName, AggregationRequest query, bool limited = false)
187+
{
188+
return (await _db.ExecuteAsync(SearchCommandBuilder.ProfileAggregate(indexName, query, limited)))
189+
.ParseProfileAggregateResult(query);
190+
}
176191

177192
/// <inheritdoc/>
178193
public async Task<SearchResult> SearchAsync(string indexName, Query q)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Xunit;
2+
3+
namespace NRedisStack.Tests;
4+
5+
public static class CustomAssertions
6+
{
7+
// Generic method to assert that 'actual' is greater than 'expected'
8+
public static void GreaterThan<T>(T actual, T expected) where T : IComparable<T>
9+
{
10+
Assert.True(actual.CompareTo(expected) > 0,
11+
$"Failure: Expected value to be greater than {expected}, but found {actual}.");
12+
}
13+
14+
// Generic method to assert that 'actual' is less than 'expected'
15+
public static void LessThan<T>(T actual, T expected) where T : IComparable<T>
16+
{
17+
Assert.True(actual.CompareTo(expected) < 0,
18+
$"Failure: Expected value to be less than {expected}, but found {actual}.");
19+
}
20+
}

0 commit comments

Comments
 (0)