Skip to content

Commit 607d693

Browse files
committed
fix build errors
1 parent c7cafe7 commit 607d693

16 files changed

+109
-115
lines changed

src/NRedisStack/CoreCommands/CoreCommands.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class CoreCommands
99
/// <summary>
1010
/// Sets information specific to the client or connection.
1111
/// </summary>
12+
/// <param name="db">the database to query</param>
1213
/// <param name="attr">which attribute to set</param>
1314
/// <param name="value">the attribute value</param>
1415
/// <returns><see langword="true"/> if the attribute name was successfully set, Error otherwise.</returns>

src/NRedisStack/CoreCommands/CoreCommandsAsync.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class CoreCommandsAsync //: ICoreCommandsAsync
99
/// <summary>
1010
/// Sets information specific to the client or connection.
1111
/// </summary>
12+
/// <param name="db">the database to query</param>
1213
/// <param name="attr">which attribute to set</param>
1314
/// <param name="value">the attribute value</param>
1415
/// <returns><see langword="true"/> if the attribute name was successfully set, Error otherwise.</returns>

src/NRedisStack/Json/JsonCommands.cs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ public int SetFromDirectory(RedisValue path, string filesPath, When when = When.
113113

114114
if (result.IsNull)
115115
{
116-
return Array.Empty<bool?>();
116+
return [];
117117
}
118118

119-
if (result.Type == ResultType.Integer)
119+
if (result.Resp2Type == ResultType.Integer)
120120
{
121-
return new bool?[] { (long)result == 1 };
121+
return [(long)result == 1];
122122
}
123123

124124
return ((RedisResult[])result!).Select(x => (bool?)((long)x == 1)).ToArray();
@@ -129,18 +129,14 @@ public JsonType[] Type(RedisKey key, string? path = null)
129129
{
130130
RedisResult result = _db.Execute(JsonCommandBuilder.Type(key, path));
131131

132-
if (result.Type == ResultType.MultiBulk)
132+
return result.Resp2Type switch
133133
{
134-
return ((RedisResult[])result!).Select(x => (JsonType)Enum.Parse(typeof(JsonType), x.ToString()!.ToUpper())).ToArray();
135-
}
136-
137-
if (result.Type == ResultType.BulkString)
138-
{
139-
return new[] { (JsonType)Enum.Parse(typeof(JsonType), result.ToString()!.ToUpper()) };
140-
}
141-
142-
return Array.Empty<JsonType>();
143-
134+
ResultType.Array => ((RedisResult[])result!)
135+
.Select(x => (JsonType)Enum.Parse(typeof(JsonType), x.ToString()!.ToUpper()))
136+
.ToArray(),
137+
ResultType.BulkString => new[] { (JsonType)Enum.Parse(typeof(JsonType), result.ToString()!.ToUpper()) },
138+
_ => []
139+
};
144140
}
145141

146142
public long DebugMemory(string key, string? path = null)
@@ -177,17 +173,12 @@ public RedisResult[] ArrPop(RedisKey key, string? path = null, long? index = nul
177173
{
178174
RedisResult result = _db.Execute(JsonCommandBuilder.ArrPop(key, path, index));
179175

180-
if (result.Type == ResultType.MultiBulk)
176+
return result.Resp2Type switch
181177
{
182-
return (RedisResult[])result!;
183-
}
184-
185-
if (result.Type == ResultType.BulkString)
186-
{
187-
return new[] { result };
188-
}
189-
190-
return Array.Empty<RedisResult>();
178+
ResultType.Array => (RedisResult[])result!,
179+
ResultType.BulkString => new[] { result },
180+
_ => []
181+
};
191182
}
192183

193184
/// <inheritdoc/>
@@ -224,10 +215,10 @@ public RedisResult Get(RedisKey key, string[] paths, RedisValue? indent = null,
224215
}
225216

226217
/// <inheritdoc/>
227-
public T? Get<T>(RedisKey key, string path = "$", JsonSerializerOptions? serializerOptions = default)
218+
public T? Get<T>(RedisKey key, string path = "$", JsonSerializerOptions? serializerOptions = null)
228219
{
229220
var res = _db.Execute(JsonCommandBuilder.Get<T>(key, path));
230-
if (res.Type == ResultType.BulkString && !res.IsNull)
221+
if (res.Resp2Type == ResultType.BulkString && !res.IsNull)
231222
{
232223
var arr = JsonSerializer.Deserialize<JsonArray>(res.ToString()!);
233224
if (arr?.Count > 0)

src/NRedisStack/Json/JsonCommandsAsync.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,12 @@ public async Task<RedisResult[]> ArrPopAsync(RedisKey key, string? path = null,
4040
{
4141
RedisResult result = await _db.ExecuteAsync(JsonCommandBuilder.ArrPop(key, path, index));
4242

43-
if (result.Type == ResultType.MultiBulk)
43+
return result.Resp2Type switch
4444
{
45-
return (RedisResult[])result!;
46-
}
47-
48-
if (result.Type == ResultType.BulkString)
49-
{
50-
return new[] { result };
51-
}
52-
53-
return Array.Empty<RedisResult>();
45+
ResultType.Array => (RedisResult[])result!,
46+
ResultType.BulkString => new[] { result },
47+
_ => []
48+
};
5449
}
5550

5651
public async Task<long?[]> ArrTrimAsync(RedisKey key, string path, long start, long stop) =>
@@ -82,10 +77,10 @@ public async Task<RedisResult> GetAsync(RedisKey key, string[] paths, RedisValue
8277
return await _db.ExecuteAsync(JsonCommandBuilder.Get(key, paths, indent, newLine, space));
8378
}
8479

85-
public async Task<T?> GetAsync<T>(RedisKey key, string path = "$", JsonSerializerOptions? serializerOptions = default)
80+
public async Task<T?> GetAsync<T>(RedisKey key, string path = "$", JsonSerializerOptions? serializerOptions = null)
8681
{
8782
var res = await _db.ExecuteAsync(JsonCommandBuilder.Get<T>(key, path));
88-
if (res.Type == ResultType.BulkString && !res.IsNull)
83+
if (res.Resp2Type == ResultType.BulkString && !res.IsNull)
8984
{
9085
var arr = JsonSerializer.Deserialize<JsonArray>(res.ToString()!);
9186
if (arr?.Count > 0)
@@ -218,12 +213,12 @@ public async Task<int> SetFromDirectoryAsync(RedisValue path, string filesPath,
218213

219214
if (result.IsNull)
220215
{
221-
return Array.Empty<bool?>();
216+
return [];
222217
}
223218

224-
if (result.Type == ResultType.Integer)
219+
if (result.Resp2Type == ResultType.Integer)
225220
{
226-
return new bool?[] { (long)result == 1 };
221+
return [(long)result == 1];
227222
}
228223

229224
return ((RedisResult[])result!).Select(x => (bool?)((long)x == 1)).ToArray();
@@ -233,12 +228,12 @@ public async Task<JsonType[]> TypeAsync(RedisKey key, string? path = null)
233228
{
234229
RedisResult result = await _db.ExecuteAsync(JsonCommandBuilder.Type(key, path));
235230

236-
if (result.Type == ResultType.MultiBulk)
231+
if (result.Resp2Type == ResultType.Array)
237232
{
238233
return ((RedisResult[])result!).Select(x => (JsonType)Enum.Parse(typeof(JsonType), x.ToString()!.ToUpper())).ToArray();
239234
}
240235

241-
if (result.Type == ResultType.BulkString)
236+
if (result.Resp2Type == ResultType.BulkString)
242237
{
243238
return new[] { (JsonType)Enum.Parse(typeof(JsonType), result.ToString()!.ToUpper()) };
244239
}

src/NRedisStack/ResponseParser.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static long[] ToLongArray(this RedisResult result)
8181

8282
public static TimeStamp ToTimeStamp(this RedisResult result)
8383
{
84-
if (result.Type == ResultType.None) return null!;
84+
if (result.Resp2Type == ResultType.None) return null!;
8585
return new TimeStamp((long)result);
8686
}
8787

@@ -508,7 +508,7 @@ public static TimeSeriesInformation ToTimeSeriesInfo(this RedisResult result)
508508
// for (int i = 0; i < res.Length; i += 2)
509509
// {
510510
// var val = res[i + 1];
511-
// if (val.Type != ResultType.MultiBulk)
511+
// if (val.Type != ResultType.Array)
512512
// {
513513
// info.Add((string)res[i], (RedisValue)val);
514514
// }
@@ -587,9 +587,9 @@ public static List<string> ToStringList(this RedisResult result)
587587
return Array.Empty<long?>();
588588
}
589589

590-
if (result.Type == ResultType.Integer)
590+
if (result.Resp2Type == ResultType.Integer)
591591
{
592-
return new[] { (long?)result };
592+
return [(long?)result];
593593
}
594594

595595
return ((RedisResult[])result!).Select(x => (long?)x).ToArray();
@@ -604,7 +604,7 @@ public static IEnumerable<HashSet<string>> ToHashSets(this RedisResult result)
604604

605605
var res = (RedisResult[])result!;
606606
var sets = new List<HashSet<string>>();
607-
if (res.All(x => x.Type != ResultType.MultiBulk))
607+
if (res.All(x => x.Resp2Type != ResultType.Array))
608608
{
609609
var keys = res.Select(x => x.ToString()!);
610610
sets.Add(new HashSet<string>(keys));
@@ -614,7 +614,7 @@ public static IEnumerable<HashSet<string>> ToHashSets(this RedisResult result)
614614
foreach (var arr in res)
615615
{
616616
var set = new HashSet<string>();
617-
if (arr.Type == ResultType.MultiBulk)
617+
if (arr.Resp2Type == ResultType.Array)
618618
{
619619
var resultArr = (RedisResult[])arr!;
620620
foreach (var item in resultArr)
@@ -679,7 +679,7 @@ public static Dictionary<string, RedisResult> ToStringRedisResultDictionary(this
679679
}
680680
else
681681
{
682-
dict.Add(arr[0].ToString()!, null);
682+
dict.Add(arr[0].ToString()!, null!);
683683
}
684684
}
685685
return dict;

src/NRedisStack/Search/AggregationResult.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public sealed class AggregationResult
77
{
88
public long TotalResults { get; }
99
private readonly Dictionary<string, object>[] _results;
10-
private Dictionary<string, RedisValue>[] _resultsAsRedisValues;
10+
private Dictionary<string, RedisValue>[]? _resultsAsRedisValues;
1111

1212
public long CursorId { get; }
1313

@@ -29,7 +29,7 @@ internal AggregationResult(RedisResult result, long cursorId = -1)
2929
{
3030
var key = (string)raw[j++]!;
3131
var val = raw[j++];
32-
if (val.Type == ResultType.MultiBulk)
32+
if (val.Resp2Type == ResultType.Array)
3333
{
3434
cur.Add(key, ConvertMultiBulkToObject((RedisResult[])val!));
3535
}
@@ -57,7 +57,7 @@ internal AggregationResult(RedisResult result, long cursorId = -1)
5757
/// <returns>object</returns>
5858
private object ConvertMultiBulkToObject(IEnumerable<RedisResult> multiBulkArray)
5959
{
60-
return multiBulkArray.Select(item => item.Type == ResultType.MultiBulk
60+
return multiBulkArray.Select(item => item.Resp2Type == ResultType.Array
6161
? ConvertMultiBulkToObject((RedisResult[])item!)
6262
: (RedisValue)item)
6363
.ToList();
@@ -73,7 +73,7 @@ private object ConvertMultiBulkToObject(IEnumerable<RedisResult> multiBulkArray)
7373
[Obsolete("This method is deprecated and will be removed in future versions. Please use 'GetRow' instead.")]
7474
public IReadOnlyList<Dictionary<string, RedisValue>> GetResults()
7575
{
76-
return getResultsAsRedisValues();
76+
return GetResultsAsRedisValues();
7777
}
7878

7979
/// <summary>
@@ -86,20 +86,18 @@ public IReadOnlyList<Dictionary<string, RedisValue>> GetResults()
8686
/// </returns>
8787
[Obsolete("This method is deprecated and will be removed in future versions. Please use 'GetRow' instead.")]
8888
public Dictionary<string, RedisValue>? this[int index]
89-
=> index >= getResultsAsRedisValues().Length ? null : getResultsAsRedisValues()[index];
89+
=> index >= GetResultsAsRedisValues().Length ? null : GetResultsAsRedisValues()[index];
9090

9191
public Row GetRow(int index)
9292
{
9393
return index >= _results.Length ? default : new Row(_results[index]);
9494
}
9595

96-
private Dictionary<string, RedisValue>[] getResultsAsRedisValues()
96+
private Dictionary<string, RedisValue>[] GetResultsAsRedisValues()
9797
{
98-
if (_resultsAsRedisValues == null)
99-
_resultsAsRedisValues = _results.Select(dict => dict.ToDictionary(
100-
kvp => kvp.Key,
101-
kvp => kvp.Value is RedisValue value ? value : RedisValue.Null
102-
)).ToArray();
103-
return _resultsAsRedisValues;
98+
return _resultsAsRedisValues ??= _results.Select(dict => dict.ToDictionary(
99+
kvp => kvp.Key,
100+
kvp => kvp.Value is RedisValue value ? value : RedisValue.Null
101+
)).ToArray();
104102
}
105103
}

src/NRedisStack/Search/DataTypes/InfoResult.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ namespace NRedisStack.Search.DataTypes;
66
public class InfoResult
77
{
88
private readonly Dictionary<string, RedisResult> _all = new();
9-
private Dictionary<string, RedisResult>[] _attributes;
10-
private Dictionary<string, RedisResult> _indexOption;
11-
private Dictionary<string, RedisResult> _gcStats;
12-
private Dictionary<string, RedisResult> _cursorStats;
9+
private Dictionary<string, RedisResult>[]? _attributes;
10+
private Dictionary<string, RedisResult>? _indexOption;
11+
private Dictionary<string, RedisResult>? _gcStats;
12+
private Dictionary<string, RedisResult>? _cursorStats;
1313

1414
private static readonly string[] booleanAttributes = { "SORTABLE", "UNF", "NOSTEM", "NOINDEX", "CASESENSITIVE", "WITHSUFFIXTRIE", "INDEXEMPTY", "INDEXMISSING" };
1515
public string IndexName => GetString("index_name")!;
16-
public Dictionary<string, RedisResult> IndexOption => _indexOption = _indexOption ?? GetRedisResultDictionary("index_options")!;
17-
public Dictionary<string, RedisResult>[] Attributes => _attributes = _attributes ?? GetAttributesAsDictionaryArray()!;
16+
public Dictionary<string, RedisResult> IndexOption => _indexOption ??= GetRedisResultDictionary("index_options")!;
17+
public Dictionary<string, RedisResult>[] Attributes => _attributes ??= GetAttributesAsDictionaryArray()!;
1818
public long NumDocs => GetLong("num_docs");
1919
public string MaxDocId => GetString("max_doc_id")!;
2020
public long NumTerms => GetLong("num_terms");
@@ -54,9 +54,9 @@ public class InfoResult
5454
public long NumberOfUses => GetLong("number_of_uses");
5555

5656

57-
public Dictionary<string, RedisResult> GcStats => _gcStats = _gcStats ?? GetRedisResultDictionary("gc_stats")!;
57+
public Dictionary<string, RedisResult> GcStats => _gcStats ??= GetRedisResultDictionary("gc_stats")!;
5858

59-
public Dictionary<string, RedisResult> CursorStats => _cursorStats = _cursorStats ?? GetRedisResultDictionary("cursor_stats")!;
59+
public Dictionary<string, RedisResult> CursorStats => _cursorStats ??= GetRedisResultDictionary("cursor_stats")!;
6060

6161
public InfoResult(RedisResult result)
6262
{
@@ -113,7 +113,7 @@ private double GetDouble(string key)
113113
IEnumerator<RedisResult> results = enumerable.GetEnumerator();
114114
while (results.MoveNext())
115115
{
116-
string attribute = (string)results.Current;
116+
string attribute = (string)results.Current!;
117117
// if its boolean attributes add itself to the dictionary and continue
118118
if (booleanAttributes.Contains(attribute))
119119
{

src/NRedisStack/Search/ISearchCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public interface ISearchCommands
167167
/// <summary>
168168
/// Return information and statistics on the index.
169169
/// </summary>
170-
/// <param name="key">The name of the index.</param>
170+
/// <param name="index">The name of the index.</param>
171171
/// <returns>Dictionary of key and value with information about the index</returns>
172172
/// <remarks><seealso href="https://redis.io/commands/ft.info"/></remarks>
173173
InfoResult Info(RedisValue index);

src/NRedisStack/Search/ISearchCommandsAsync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public interface ISearchCommandsAsync
166166
/// <summary>
167167
/// Return information and statistics on the index.
168168
/// </summary>
169-
/// <param name="key">The name of the index.</param>
169+
/// <param name="index">The name of the index.</param>
170170
/// <returns>Dictionary of key and value with information about the index</returns>
171171
/// <remarks><seealso href="https://redis.io/commands/ft.info"/></remarks>
172172
Task<InfoResult> InfoAsync(RedisValue index);

src/NRedisStack/Search/Query.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ public Query ReturnFields(params string[] fields)
563563
/// <summary>
564564
/// Result's projection - the fields to return by the query
565565
/// </summary>
566-
/// <param name="field">field a list of TEXT fields in the schemas</param>
566+
/// <param name="fields">field a list of TEXT fields in the schemas</param>
567567
/// <returns>the query object itself</returns>
568568
public Query ReturnFields(params FieldName[] fields)
569569
{
@@ -683,10 +683,10 @@ public Query SetInOrder()
683683
/// <summary>
684684
/// Set the query to use a custom query expander instead of the stemmer
685685
/// </summary>
686-
/// <param name="field the expander field's name"></param>
686+
/// <param name="field">the expander field's name</param>
687687
/// <returns>the query object itself</returns>
688688

689-
public Query SetExpander(String field)
689+
public Query SetExpander(string field)
690690
{
691691
_expander = field;
692692
return this;

0 commit comments

Comments
 (0)