|
| 1 | +using System.Runtime.CompilerServices; |
| 2 | +using RESPite.Messages; |
| 3 | +using StackExchange.Redis; |
| 4 | + |
| 5 | +// ReSharper disable InconsistentNaming |
| 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 ListCommands Lists(this in RespContext context) |
| 12 | + => ref Unsafe.As<RespContext, ListCommands>(ref Unsafe.AsRef(in context)); |
| 13 | +} |
| 14 | + |
| 15 | +public readonly struct ListCommands(in RespContext context) |
| 16 | +{ |
| 17 | + public readonly RespContext Context = context; // important: this is the only field |
| 18 | +} |
| 19 | + |
| 20 | +internal static partial class ListCommandsExtensions |
| 21 | +{ |
| 22 | + /* |
| 23 | + [RespCommand] |
| 24 | + public static partial RespOperation<RedisValue> BLMove( |
| 25 | + this in ListCommands context, |
| 26 | + RedisKey source, |
| 27 | + RedisKey destination, |
| 28 | + ListSide sourceSide, |
| 29 | + ListSide destinationSide, |
| 30 | + double timeoutSeconds); |
| 31 | +
|
| 32 | + [RespCommand] |
| 33 | + public static partial RespOperation<RedisValue[]> BLMPop( |
| 34 | + this in ListCommands context, |
| 35 | + [RespKey] RedisKey[] keys, |
| 36 | + ListSide side, |
| 37 | + long count, |
| 38 | + double timeoutSeconds); |
| 39 | +
|
| 40 | + [RespCommand] |
| 41 | + public static partial RespOperation<RedisValue> BLPop( |
| 42 | + this in ListCommands context, |
| 43 | + [RespKey] RedisKey[] keys, |
| 44 | + double timeoutSeconds); |
| 45 | +
|
| 46 | + [RespCommand] |
| 47 | + public static partial RespOperation<RedisValue> BRPop( |
| 48 | + this in ListCommands context, |
| 49 | + [RespKey] RedisKey[] keys, |
| 50 | + double timeoutSeconds); |
| 51 | +
|
| 52 | + [RespCommand] |
| 53 | + public static partial RespOperation<RedisValue> BRPopLPush( |
| 54 | + this in ListCommands context, |
| 55 | + RedisKey source, |
| 56 | + RedisKey destination, |
| 57 | + double timeoutSeconds); |
| 58 | + */ |
| 59 | + |
| 60 | + [RespCommand] |
| 61 | + public static partial RespOperation<RedisValue> LIndex(this in ListCommands context, RedisKey key, long index); |
| 62 | + |
| 63 | + [RespCommand(Formatter = "LInsertFormatter.Instance")] |
| 64 | + public static partial RespOperation<long> LInsert( |
| 65 | + this in ListCommands context, |
| 66 | + RedisKey key, |
| 67 | + bool insertBefore, |
| 68 | + RedisValue pivot, |
| 69 | + RedisValue element); |
| 70 | + |
| 71 | + private sealed class |
| 72 | + LInsertFormatter : IRespFormatter<(RedisKey Key, bool InsertBefore, RedisValue Pivot, RedisValue Element)> |
| 73 | + { |
| 74 | + public static readonly LInsertFormatter Instance = new(); |
| 75 | + private LInsertFormatter() { } |
| 76 | + |
| 77 | + public void Format( |
| 78 | + scoped ReadOnlySpan<byte> command, |
| 79 | + ref RespWriter writer, |
| 80 | + in (RedisKey Key, bool InsertBefore, RedisValue Pivot, RedisValue Element) request) |
| 81 | + { |
| 82 | + writer.WriteCommand(command, 4); |
| 83 | + writer.Write(request.Key); |
| 84 | + writer.WriteRaw(request.InsertBefore ? "$6\r\nBEFORE\r\n"u8 : "$5\r\nAFTER\r\n"u8); |
| 85 | + writer.Write(request.Pivot); |
| 86 | + writer.Write(request.Element); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + [RespCommand] |
| 91 | + public static partial RespOperation<long> LLen(this in ListCommands context, RedisKey key); |
| 92 | + |
| 93 | + [RespCommand] |
| 94 | + public static partial RespOperation<RedisValue> LMove( |
| 95 | + this in ListCommands context, |
| 96 | + RedisKey source, |
| 97 | + RedisKey destination, |
| 98 | + ListSide sourceSide, |
| 99 | + ListSide destinationSide); |
| 100 | + |
| 101 | + [RespCommand] |
| 102 | + public static partial RespOperation<RedisValue> LPop(this in ListCommands context, RedisKey key); |
| 103 | + |
| 104 | + [RespCommand] |
| 105 | + public static partial RespOperation<RedisValue[]> LPop(this in ListCommands context, RedisKey key, long count); |
| 106 | + |
| 107 | + [RespCommand(Parser = "RespParsers.Int64Index")] |
| 108 | + public static partial RespOperation<long> LPos( |
| 109 | + this in ListCommands context, |
| 110 | + RedisKey key, |
| 111 | + RedisValue element, |
| 112 | + [RespPrefix("RANK"), RespIgnore(1)] long rank = 1, |
| 113 | + [RespPrefix("MAXLEN"), RespIgnore(0)] long maxLen = 0); |
| 114 | + |
| 115 | + [RespCommand] |
| 116 | + public static partial RespOperation<long[]> LPos( |
| 117 | + this in ListCommands context, |
| 118 | + RedisKey key, |
| 119 | + RedisValue element, |
| 120 | + [RespPrefix("RANK"), RespIgnore(1)] long rank, |
| 121 | + [RespPrefix("MAXLEN"), RespIgnore(0)] long maxLen, |
| 122 | + [RespPrefix("COUNT")] long count); |
| 123 | + |
| 124 | + [RespCommand] |
| 125 | + public static partial RespOperation<long> LPush(this in ListCommands context, RedisKey key, RedisValue element); |
| 126 | + |
| 127 | + [RespCommand] |
| 128 | + public static partial RespOperation<long> LPush(this in ListCommands context, RedisKey key, RedisValue[] elements); |
| 129 | + |
| 130 | + [RespCommand] |
| 131 | + public static partial RespOperation<long> LPushX(this in ListCommands context, RedisKey key, RedisValue element); |
| 132 | + |
| 133 | + [RespCommand] |
| 134 | + public static partial RespOperation<long> LPushX(this in ListCommands context, RedisKey key, RedisValue[] elements); |
| 135 | + |
| 136 | + [RespCommand] |
| 137 | + public static partial RespOperation<RedisValue[]> LRange( |
| 138 | + this in ListCommands context, |
| 139 | + RedisKey key, |
| 140 | + long start, |
| 141 | + long stop); |
| 142 | + |
| 143 | + [RespCommand] |
| 144 | + public static partial RespOperation<long> LRem( |
| 145 | + this in ListCommands context, |
| 146 | + RedisKey key, |
| 147 | + long count, |
| 148 | + RedisValue element); |
| 149 | + |
| 150 | + [RespCommand] |
| 151 | + public static partial RespOperation LSet( |
| 152 | + this in ListCommands context, |
| 153 | + RedisKey key, |
| 154 | + long index, |
| 155 | + RedisValue element); |
| 156 | + |
| 157 | + [RespCommand] |
| 158 | + public static partial RespOperation LTrim(this in ListCommands context, RedisKey key, long start, long stop); |
| 159 | + |
| 160 | + [RespCommand] |
| 161 | + public static partial RespOperation<RedisValue> RPop(this in ListCommands context, RedisKey key); |
| 162 | + |
| 163 | + [RespCommand] |
| 164 | + public static partial RespOperation<RedisValue[]> RPop(this in ListCommands context, RedisKey key, long count); |
| 165 | + |
| 166 | + [RespCommand] |
| 167 | + public static partial RespOperation<RedisValue> RPopLPush(this in ListCommands context, RedisKey source, |
| 168 | + RedisKey destination); |
| 169 | + |
| 170 | + [RespCommand] |
| 171 | + public static partial RespOperation<long> RPush(this in ListCommands context, RedisKey key, RedisValue element); |
| 172 | + |
| 173 | + [RespCommand] |
| 174 | + public static partial RespOperation<long> RPush(this in ListCommands context, RedisKey key, RedisValue[] elements); |
| 175 | + |
| 176 | + [RespCommand] |
| 177 | + public static partial RespOperation<long> RPushX(this in ListCommands context, RedisKey key, RedisValue element); |
| 178 | + |
| 179 | + [RespCommand] |
| 180 | + public static partial RespOperation<long> RPushX(this in ListCommands context, RedisKey key, RedisValue[] elements); |
| 181 | + |
| 182 | + [RespCommand(Parser = "RespParsers.ListPopResult")] |
| 183 | + public static partial RespOperation<ListPopResult> LMPop( |
| 184 | + this in ListCommands context, |
| 185 | + [RespPrefix, RespKey] RedisKey[] keys, |
| 186 | + ListSide side, |
| 187 | + [RespIgnore(1), RespPrefix("COUNT")] long count = 1); |
| 188 | +} |
0 commit comments