Skip to content

Commit c195faa

Browse files
committed
rationalize
1 parent daee242 commit c195faa

5 files changed

Lines changed: 29 additions & 42 deletions

File tree

src/StackExchange.Redis/Enums/RedisCommand.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ internal enum RedisCommand
270270
ZCARD,
271271
ZCOUNT,
272272
ZDIFF,
273-
ZDIFFCARD,
274273
ZDIFFSTORE,
275274
ZINCRBY,
276275
ZINTER,
@@ -298,7 +297,6 @@ internal enum RedisCommand
298297
ZSCAN,
299298
ZSCORE,
300299
ZUNION,
301-
ZUNIONCARD,
302300
ZUNIONSTORE,
303301

304302
UNKNOWN,
@@ -561,7 +559,6 @@ internal static bool IsPrimaryOnly(this RedisCommand command)
561559
case RedisCommand.ZCARD:
562560
case RedisCommand.ZCOUNT:
563561
case RedisCommand.ZDIFF:
564-
case RedisCommand.ZDIFFCARD:
565562
case RedisCommand.ZINTER:
566563
case RedisCommand.ZINTERCARD:
567564
case RedisCommand.ZLEXCOUNT:
@@ -578,7 +575,6 @@ internal static bool IsPrimaryOnly(this RedisCommand command)
578575
case RedisCommand.ZSCAN:
579576
case RedisCommand.ZSCORE:
580577
case RedisCommand.ZUNION:
581-
case RedisCommand.ZUNIONCARD:
582578
case RedisCommand.UNKNOWN:
583579
case RedisCommand.VCARD:
584580
case RedisCommand.VDIM:

src/StackExchange.Redis/Enums/SetOperation.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,38 @@ public enum SetOperation
2525

2626
internal static class SetOperationExtensions
2727
{
28-
internal static RedisCommand ToBasicCommand(this SetOperation operation) => operation switch
28+
internal static RedisCommand ToSetCommand(this SetOperation operation) => operation switch
29+
{
30+
SetOperation.Union => RedisCommand.SUNION,
31+
SetOperation.Intersect => RedisCommand.SINTER,
32+
SetOperation.Difference => RedisCommand.SDIFF,
33+
_ => OutOfRange(operation),
34+
};
35+
36+
internal static RedisCommand ToSetStoreCommand(this SetOperation operation) => operation switch
37+
{
38+
SetOperation.Union => RedisCommand.SUNIONSTORE,
39+
SetOperation.Intersect => RedisCommand.SINTERSTORE,
40+
SetOperation.Difference => RedisCommand.SDIFFSTORE,
41+
_ => OutOfRange(operation),
42+
};
43+
44+
internal static RedisCommand ToSortedSetCommand(this SetOperation operation) => operation switch
2945
{
3046
SetOperation.Union => RedisCommand.ZUNION,
3147
SetOperation.Intersect => RedisCommand.ZINTER,
3248
SetOperation.Difference => RedisCommand.ZDIFF,
3349
_ => OutOfRange(operation),
3450
};
3551

36-
internal static RedisCommand ToStoreCommand(this SetOperation operation) => operation switch
52+
internal static RedisCommand ToSortedSetStoreCommand(this SetOperation operation) => operation switch
3753
{
3854
SetOperation.Union => RedisCommand.ZUNIONSTORE,
3955
SetOperation.Intersect => RedisCommand.ZINTERSTORE,
4056
SetOperation.Difference => RedisCommand.ZDIFFSTORE,
4157
_ => OutOfRange(operation),
4258
};
4359

44-
internal static RedisCommand ToCardinalityCommand(this SetOperation operation) => operation switch
45-
{
46-
SetOperation.Union => RedisCommand.ZUNIONCARD,
47-
SetOperation.Intersect => RedisCommand.ZINTERCARD,
48-
SetOperation.Difference => RedisCommand.ZDIFFCARD,
49-
_ => OutOfRange(operation),
50-
};
51-
5260
private static RedisCommand OutOfRange(SetOperation operation) =>
5361
throw new ArgumentOutOfRangeException(nameof(operation), operation, null);
5462
}

src/StackExchange.Redis/RedisDatabase.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,49 +2056,49 @@ public Task<long> SetAddAsync(RedisKey key, RedisValue[] values, CommandFlags fl
20562056

20572057
public RedisValue[] SetCombine(SetOperation operation, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None)
20582058
{
2059-
var msg = Message.Create(Database, flags, SetOperationCommand(operation, false), first, second);
2059+
var msg = Message.Create(Database, flags, operation.ToSetCommand(), first, second);
20602060
return ExecuteSync(msg, ResultProcessor.RedisValueArray, defaultValue: Array.Empty<RedisValue>());
20612061
}
20622062

20632063
public RedisValue[] SetCombine(SetOperation operation, RedisKey[] keys, CommandFlags flags = CommandFlags.None)
20642064
{
2065-
var msg = Message.Create(Database, flags, SetOperationCommand(operation, false), keys);
2065+
var msg = Message.Create(Database, flags, operation.ToSetCommand(), keys);
20662066
return ExecuteSync(msg, ResultProcessor.RedisValueArray, defaultValue: Array.Empty<RedisValue>());
20672067
}
20682068

20692069
public long SetCombineAndStore(SetOperation operation, RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None)
20702070
{
2071-
var msg = Message.Create(Database, flags, SetOperationCommand(operation, true), destination, first, second);
2071+
var msg = Message.Create(Database, flags, operation.ToSetStoreCommand(), destination, first, second);
20722072
return ExecuteSync(msg, ResultProcessor.Int64);
20732073
}
20742074

20752075
public long SetCombineAndStore(SetOperation operation, RedisKey destination, RedisKey[] keys, CommandFlags flags = CommandFlags.None)
20762076
{
2077-
var msg = Message.Create(Database, flags, SetOperationCommand(operation, true), destination, keys);
2077+
var msg = Message.Create(Database, flags, operation.ToSetStoreCommand(), destination, keys);
20782078
return ExecuteSync(msg, ResultProcessor.Int64);
20792079
}
20802080

20812081
public Task<long> SetCombineAndStoreAsync(SetOperation operation, RedisKey destination, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None)
20822082
{
2083-
var msg = Message.Create(Database, flags, SetOperationCommand(operation, true), destination, first, second);
2083+
var msg = Message.Create(Database, flags, operation.ToSetStoreCommand(), destination, first, second);
20842084
return ExecuteAsync(msg, ResultProcessor.Int64);
20852085
}
20862086

20872087
public Task<long> SetCombineAndStoreAsync(SetOperation operation, RedisKey destination, RedisKey[] keys, CommandFlags flags = CommandFlags.None)
20882088
{
2089-
var msg = Message.Create(Database, flags, SetOperationCommand(operation, true), destination, keys);
2089+
var msg = Message.Create(Database, flags, operation.ToSetStoreCommand(), destination, keys);
20902090
return ExecuteAsync(msg, ResultProcessor.Int64);
20912091
}
20922092

20932093
public Task<RedisValue[]> SetCombineAsync(SetOperation operation, RedisKey first, RedisKey second, CommandFlags flags = CommandFlags.None)
20942094
{
2095-
var msg = Message.Create(Database, flags, SetOperationCommand(operation, false), first, second);
2095+
var msg = Message.Create(Database, flags, operation.ToSetCommand(), first, second);
20962096
return ExecuteAsync(msg, ResultProcessor.RedisValueArray, defaultValue: Array.Empty<RedisValue>());
20972097
}
20982098

20992099
public Task<RedisValue[]> SetCombineAsync(SetOperation operation, RedisKey[] keys, CommandFlags flags = CommandFlags.None)
21002100
{
2101-
var msg = Message.Create(Database, flags, SetOperationCommand(operation, false), keys);
2101+
var msg = Message.Create(Database, flags, operation.ToSetCommand(), keys);
21022102
return ExecuteAsync(msg, ResultProcessor.RedisValueArray, defaultValue: Array.Empty<RedisValue>());
21032103
}
21042104

@@ -4516,7 +4516,7 @@ private Message GetSortMessage(RedisKey destination, RedisKey key, long skip, lo
45164516

45174517
private Message GetSortedSetCombineAndStoreCommandMessage(SetOperation operation, RedisKey destination, RedisKey[] keys, double[]? weights, Aggregate aggregate, CommandFlags flags)
45184518
{
4519-
var command = operation.ToStoreCommand();
4519+
var command = operation.ToSortedSetStoreCommand();
45204520
if (keys == null)
45214521
{
45224522
throw new ArgumentNullException(nameof(keys));
@@ -4589,7 +4589,7 @@ private Message GetSortedSetLengthMessage(RedisKey key, double min, double max,
45894589
}
45904590

45914591
private Message GetSortedSetIntersectionLengthMessage(RedisKey[] keys, long limit, CommandFlags flags)
4592-
=> new SetOperationCardinalityMessage(Database, flags, SetOperation.Intersect, keys, limit);
4592+
=> new SetOperationCardinalityMessage(Database, flags, RedisCommand.ZINTERCARD, keys, limit);
45934593

45944594
private Message GetSortedSetRangeByScoreMessage(RedisKey key, double start, double stop, Exclude exclude, Order order, long skip, long take, CommandFlags flags, bool withScores)
45954595
{
@@ -5299,14 +5299,6 @@ private Message GetStringSetAndGetMessage(
52995299
_ => Message.Create(Database, flags, RedisCommand.DECRBY, key, -value),
53005300
};
53015301

5302-
private static RedisCommand SetOperationCommand(SetOperation operation, bool store) => operation switch
5303-
{
5304-
SetOperation.Difference => store ? RedisCommand.SDIFFSTORE : RedisCommand.SDIFF,
5305-
SetOperation.Intersect => store ? RedisCommand.SINTERSTORE : RedisCommand.SINTER,
5306-
SetOperation.Union => store ? RedisCommand.SUNIONSTORE : RedisCommand.SUNION,
5307-
_ => throw new ArgumentOutOfRangeException(nameof(operation)),
5308-
};
5309-
53105302
private CursorEnumerable<T>? TryScan<T>(RedisKey key, RedisValue pattern, int pageSize, long cursor, int pageOffset, CommandFlags flags, RedisCommand command, ResultProcessor<ScanEnumerable<T>.ScanResult> processor, out ServerEndPoint? server, bool noValues = false)
53115303
{
53125304
server = null;

src/StackExchange.Redis/SetOperationCardinalityMessage.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ internal sealed class SetOperationCardinalityMessage(
99
{
1010
private readonly RedisKey[] _keys = keys.AssertAllNonNull();
1111

12-
public SetOperationCardinalityMessage(
13-
int db,
14-
CommandFlags flags,
15-
SetOperation operation,
16-
RedisKey[] keys,
17-
long limit) : this(db, flags, operation.ToCardinalityCommand(), keys, limit)
18-
{
19-
}
20-
2112
public override int ArgCount => 1 + _keys.Length + (limit > 0 ? 2 : 0);
2213

2314
public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy) => serverSelectionStrategy.HashSlot(_keys);

src/StackExchange.Redis/SetOperationMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public SetOperationMessage(
1616
RedisKey[] keys,
1717
double[]? weights,
1818
Aggregate aggregate,
19-
bool withScores) : base(db, flags, operation.ToBasicCommand())
19+
bool withScores) : base(db, flags, operation.ToSortedSetCommand())
2020
{
2121
_keys = keys.AssertAllNonNull();
2222
if (operation == SetOperation.Difference && (weights != null || aggregate != Aggregate.Sum))

0 commit comments

Comments
 (0)