|
| 1 | +using System.Runtime.CompilerServices; |
| 2 | +using StackExchange.Redis; |
| 3 | + |
| 4 | +// ReSharper disable InconsistentNaming |
| 5 | +// ReSharper disable MemberCanBePrivate.Global |
| 6 | +namespace RESPite.StackExchange.Redis; |
| 7 | + |
| 8 | +internal static partial class RedisCommands |
| 9 | +{ |
| 10 | + // this is just a "type pun" - it should be an invisible/magic pointer cast to the JIT |
| 11 | + public static ref readonly SetCommands Sets(this in RespContext context) |
| 12 | + => ref Unsafe.As<RespContext, SetCommands>(ref Unsafe.AsRef(in context)); |
| 13 | +} |
| 14 | + |
| 15 | +public readonly struct SetCommands(in RespContext context) |
| 16 | +{ |
| 17 | + public readonly RespContext Context = context; // important: this is the only field |
| 18 | +} |
| 19 | + |
| 20 | +internal static partial class SetCommandsExtensions |
| 21 | +{ |
| 22 | + [RespCommand] |
| 23 | + public static partial RespOperation<bool> SAdd(this in SetCommands context, RedisKey key, RedisValue member); |
| 24 | + |
| 25 | + [RespCommand] |
| 26 | + public static partial RespOperation<long> SAdd(this in SetCommands context, RedisKey key, RedisValue[] members); |
| 27 | + |
| 28 | + [RespCommand] |
| 29 | + public static partial RespOperation<long> SCard(this in SetCommands context, RedisKey key); |
| 30 | + |
| 31 | + [RespCommand] |
| 32 | + public static partial RespOperation<RedisValue[]> SDiff(this in SetCommands context, RedisKey first, RedisKey second); |
| 33 | + |
| 34 | + [RespCommand] |
| 35 | + public static partial RespOperation<RedisValue[]> SDiff(this in SetCommands context, RedisKey[] keys); |
| 36 | + |
| 37 | + [RespCommand] |
| 38 | + public static partial RespOperation<long> SDiffStore(this in SetCommands context, RedisKey destination, RedisKey first, RedisKey second); |
| 39 | + |
| 40 | + [RespCommand] |
| 41 | + public static partial RespOperation<long> SDiffStore(this in SetCommands context, RedisKey destination, RedisKey[] keys); |
| 42 | + |
| 43 | + [RespCommand] |
| 44 | + public static partial RespOperation<RedisValue[]> SInter(this in SetCommands context, RedisKey first, RedisKey second); |
| 45 | + |
| 46 | + [RespCommand] |
| 47 | + public static partial RespOperation<RedisValue[]> SInter(this in SetCommands context, RedisKey[] keys); |
| 48 | + |
| 49 | + [RespCommand] |
| 50 | + public static partial RespOperation<long> SInterCard(this in SetCommands context, RedisKey first, RedisKey second, long limit = 0); |
| 51 | + |
| 52 | + [RespCommand] |
| 53 | + public static partial RespOperation<long> SInterCard(this in SetCommands context, RedisKey[] keys, long limit = 0); |
| 54 | + |
| 55 | + [RespCommand] |
| 56 | + public static partial RespOperation<long> SInterStore(this in SetCommands context, RedisKey destination, RedisKey first, RedisKey second); |
| 57 | + |
| 58 | + [RespCommand] |
| 59 | + public static partial RespOperation<long> SInterStore(this in SetCommands context, RedisKey destination, RedisKey[] keys); |
| 60 | + |
| 61 | + [RespCommand] |
| 62 | + public static partial RespOperation<bool> SIsMember(this in SetCommands context, RedisKey key, RedisValue member); |
| 63 | + |
| 64 | + [RespCommand] |
| 65 | + public static partial RespOperation<bool[]> SMIsMember(this in SetCommands context, RedisKey key, RedisValue[] members); |
| 66 | + |
| 67 | + [RespCommand] |
| 68 | + public static partial RespOperation<RedisValue[]> SMembers(this in SetCommands context, RedisKey key); |
| 69 | + |
| 70 | + [RespCommand] |
| 71 | + public static partial RespOperation<bool> SMove(this in SetCommands context, RedisKey source, RedisKey destination, RedisValue member); |
| 72 | + |
| 73 | + [RespCommand] |
| 74 | + public static partial RespOperation<RedisValue> SPop(this in SetCommands context, RedisKey key); |
| 75 | + |
| 76 | + [RespCommand] |
| 77 | + public static partial RespOperation<RedisValue[]> SPop(this in SetCommands context, RedisKey key, long count); |
| 78 | + |
| 79 | + [RespCommand] |
| 80 | + public static partial RespOperation<RedisValue> SRandMember(this in SetCommands context, RedisKey key); |
| 81 | + |
| 82 | + [RespCommand] |
| 83 | + public static partial RespOperation<RedisValue[]> SRandMember(this in SetCommands context, RedisKey key, long count); |
| 84 | + |
| 85 | + [RespCommand] |
| 86 | + public static partial RespOperation<bool> SRem(this in SetCommands context, RedisKey key, RedisValue member); |
| 87 | + |
| 88 | + [RespCommand] |
| 89 | + public static partial RespOperation<long> SRem(this in SetCommands context, RedisKey key, RedisValue[] members); |
| 90 | + |
| 91 | + [RespCommand] |
| 92 | + public static partial RespOperation<RedisValue[]> SUnion(this in SetCommands context, RedisKey first, RedisKey second); |
| 93 | + |
| 94 | + [RespCommand] |
| 95 | + public static partial RespOperation<RedisValue[]> SUnion(this in SetCommands context, RedisKey[] keys); |
| 96 | + |
| 97 | + [RespCommand] |
| 98 | + public static partial RespOperation<long> SUnionStore(this in SetCommands context, RedisKey destination, RedisKey first, RedisKey second); |
| 99 | + |
| 100 | + [RespCommand] |
| 101 | + public static partial RespOperation<long> SUnionStore(this in SetCommands context, RedisKey destination, RedisKey[] keys); |
| 102 | + |
| 103 | + internal static RespOperation<long> CombineStore( |
| 104 | + this in SetCommands context, |
| 105 | + SetOperation operation, |
| 106 | + RedisKey destination, |
| 107 | + RedisKey first, |
| 108 | + RedisKey second) => |
| 109 | + operation switch |
| 110 | + { |
| 111 | + SetOperation.Difference => context.SDiffStore(destination, first, second), |
| 112 | + SetOperation.Intersect => context.SInterStore(destination, first, second), |
| 113 | + SetOperation.Union => context.SUnionStore(destination, first, second), |
| 114 | + _ => throw new ArgumentOutOfRangeException(nameof(operation)), |
| 115 | + }; |
| 116 | + |
| 117 | + internal static RespOperation<long> CombineStore( |
| 118 | + this in SetCommands context, |
| 119 | + SetOperation operation, |
| 120 | + RedisKey destination, |
| 121 | + RedisKey[] keys) => |
| 122 | + operation switch |
| 123 | + { |
| 124 | + SetOperation.Difference => context.SDiffStore(destination, keys), |
| 125 | + SetOperation.Intersect => context.SInterStore(destination, keys), |
| 126 | + SetOperation.Union => context.SUnionStore(destination, keys), |
| 127 | + _ => throw new ArgumentOutOfRangeException(nameof(operation)), |
| 128 | + }; |
| 129 | + |
| 130 | + internal static RespOperation<RedisValue[]> Combine( |
| 131 | + this in SetCommands context, |
| 132 | + SetOperation operation, |
| 133 | + RedisKey first, |
| 134 | + RedisKey second) => |
| 135 | + operation switch |
| 136 | + { |
| 137 | + SetOperation.Difference => context.SDiff(first, second), |
| 138 | + SetOperation.Intersect => context.SInter(first, second), |
| 139 | + SetOperation.Union => context.SUnion(first, second), |
| 140 | + _ => throw new ArgumentOutOfRangeException(nameof(operation)), |
| 141 | + }; |
| 142 | + |
| 143 | + internal static RespOperation<RedisValue[]> Combine( |
| 144 | + this in SetCommands context, |
| 145 | + SetOperation operation, |
| 146 | + RedisKey[] keys) => |
| 147 | + operation switch |
| 148 | + { |
| 149 | + SetOperation.Difference => context.SDiff(keys), |
| 150 | + SetOperation.Intersect => context.SInter(keys), |
| 151 | + SetOperation.Union => context.SUnion(keys), |
| 152 | + _ => throw new ArgumentOutOfRangeException(nameof(operation)), |
| 153 | + }; |
| 154 | +} |
0 commit comments