Skip to content

Commit 4619825

Browse files
authored
Fix cluster routing of various commands (#445)
* - fix cluster routing - many operations were working by following `-MOVED`, which is inefficient (and causes a topology fetch for every miss, due to panic) - change tests to disable `-MOVED` redirection; in tests, failure is preferable * missed an endpointid in CI * skip more FT.* ops in pre-8 cluster * more FT.* pre-8 skips
1 parent ac29976 commit 4619825

File tree

8 files changed

+109
-54
lines changed

8 files changed

+109
-54
lines changed

src/NRedisStack/Auxiliary.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,31 @@ internal static void SetInfoInPipeline(this IDatabase db)
6161
}
6262
}
6363

64+
#if DEBUG
65+
private const CommandFlags Flags = CommandFlags.NoRedirect; // disable redirect, so we spot -MOVED in tests
66+
#else
67+
private const CommandFlags Flags = CommandFlags.None;
68+
#endif
6469
public static RedisResult Execute(this IDatabase db, SerializedCommand command)
6570
{
6671
db.SetInfoInPipeline();
67-
return db.Execute(command.Command, command.Args);
72+
return db.Execute(command.Command, command.Args, flags: Flags);
6873
}
6974

7075
internal static RedisResult Execute(this IServer server, int? db, SerializedCommand command)
7176
{
72-
return server.Execute(db, command.Command, command.Args);
77+
return server.Execute(db, command.Command, command.Args, flags: Flags);
7378
}
7479

7580
public static async Task<RedisResult> ExecuteAsync(this IDatabaseAsync db, SerializedCommand command)
7681
{
7782
((IDatabase)db).SetInfoInPipeline();
78-
return await db.ExecuteAsync(command.Command, command.Args);
83+
return await db.ExecuteAsync(command.Command, command.Args, flags: Flags);
7984
}
8085

8186
internal static async Task<RedisResult> ExecuteAsync(this IServer server, int? db, SerializedCommand command)
8287
{
83-
return await server.ExecuteAsync(db, command.Command, command.Args);
88+
return await server.ExecuteAsync(db, command.Command, command.Args, flags: Flags);
8489
}
8590

8691
public static List<RedisResult> ExecuteBroadcast(this IDatabase db, string command)

src/NRedisStack/Json/JsonCommandBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public static SerializedCommand Type(RedisKey key, string? path = null)
7171
public static SerializedCommand DebugMemory(string key, string? path = null)
7272
{
7373
return (path != null)
74-
? new(JSON.DEBUG, JSON.MEMORY, key, path)
75-
: new SerializedCommand(JSON.DEBUG, JSON.MEMORY, key);
74+
? new(JSON.DEBUG, JSON.MEMORY, (RedisKey)key, path)
75+
: new SerializedCommand(JSON.DEBUG, JSON.MEMORY, (RedisKey)key);
7676
}
7777

7878
public static SerializedCommand ArrAppend(RedisKey key, string? path = null, params object[] values)

src/NRedisStack/Search/SearchCommandBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,20 @@ public static SerializedCommand SpellCheck(string indexName, string query, FTSpe
196196

197197
public static SerializedCommand SugAdd(string key, string str, double score, bool increment = false, string? payload = null)
198198
{
199-
var args = new List<object> { key, str, score };
199+
var args = new List<object> { (RedisKey)key, str, score };
200200
if (increment) { args.Add(SearchArgs.INCR); }
201201
if (payload != null) { args.Add(SearchArgs.PAYLOAD); args.Add(payload); }
202202
return new(FT.SUGADD, args);
203203
}
204204

205205
public static SerializedCommand SugDel(string key, string str)
206206
{
207-
return new(FT.SUGDEL, key, str);
207+
return new(FT.SUGDEL, (RedisKey)key, str);
208208
}
209209

210210
public static SerializedCommand SugGet(string key, string prefix, bool fuzzy = false, bool withScores = false, bool withPayloads = false, int? max = null)
211211
{
212-
var args = new List<object> { key, prefix };
212+
var args = new List<object> { (RedisKey)key, prefix };
213213
if (fuzzy) { args.Add(SearchArgs.FUZZY); }
214214
if (withScores) { args.Add(SearchArgs.WITHSCORES); }
215215
if (withPayloads) { args.Add(SearchArgs.WITHPAYLOADS); }
@@ -219,7 +219,7 @@ public static SerializedCommand SugGet(string key, string prefix, bool fuzzy = f
219219

220220
public static SerializedCommand SugLen(string key)
221221
{
222-
return new(FT.SUGLEN, key);
222+
return new(FT.SUGLEN, (RedisKey)key);
223223
}
224224

225225
public static SerializedCommand SynDump(string indexName)

src/NRedisStack/Tdigest/TdigestCommandBuilder.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ public static class TdigestCommandBuilder
88
{
99
public static SerializedCommand Add(RedisKey key, params double[] values)
1010
{
11-
if (values.Length < 0) throw new ArgumentOutOfRangeException(nameof(values));
12-
var args = new string[values.Length + 1];
13-
args[0] = key.ToString();
11+
var args = new object[values.Length + 1];
12+
args[0] = key;
1413
for (int i = 0; i < values.Length; i++)
1514
{
16-
args[i + 1] = values[i].ToString();
15+
args[i + 1] = values[i];
1716
}
1817

1918
return new(TDIGEST.ADD, args);

src/NRedisStack/TimeSeries/DataTypes/TSParameters.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NRedisStack.DataTypes;
22
using NRedisStack.Literals.Enums;
3+
using StackExchange.Redis;
34

45
namespace NRedisStack;
56

@@ -17,7 +18,7 @@ internal TsBaseParams(IList<object> parameters)
1718
this.parameters = parameters;
1819
}
1920

20-
internal object[] ToArray(string key)
21+
internal object[] ToArray(RedisKey key)
2122
{
2223
parameters.Insert(0, key);
2324
return parameters.ToArray();

0 commit comments

Comments
 (0)