Skip to content

Commit 6afdfa1

Browse files
committed
finish lists
1 parent a5b5663 commit 6afdfa1

File tree

2 files changed

+204
-185
lines changed

2 files changed

+204
-185
lines changed

src/RESPite.StackExchange.Redis/RedisCommands.ListCommands.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,38 @@ public static partial RespOperation<long[]> LPos(
124124
[RespCommand]
125125
public static partial RespOperation<long> LPush(this in ListCommands context, RedisKey key, RedisValue element);
126126

127+
internal static RespOperation<long> Push(this in ListCommands context, RedisKey key, RedisValue element, ListSide side, When when)
128+
{
129+
switch (when)
130+
{
131+
case When.Always:
132+
return side == ListSide.Left ? LPush(context, key, element) : RPush(context, key, element);
133+
case When.Exists:
134+
return side == ListSide.Left ? LPushX(context, key, element) : RPushX(context, key, element);
135+
default:
136+
when.AlwaysOrExists(); // throws
137+
return default;
138+
}
139+
}
140+
141+
internal static RespOperation<long> Push(this in ListCommands context, RedisKey key, RedisValue[] elements, ListSide side, When when)
142+
{
143+
switch (when)
144+
{
145+
case When.Always when elements.Length == 1:
146+
return side == ListSide.Left ? LPush(context, key, elements[0]) : RPush(context, key, elements[0]);
147+
case When.Always when elements.Length > 1:
148+
return side == ListSide.Left ? LPush(context, key, elements) : RPush(context, key, elements);
149+
case When.Exists when elements.Length == 1:
150+
return side == ListSide.Left ? LPushX(context, key, elements[0]) : RPushX(context, key, elements[0]);
151+
case When.Exists when elements.Length > 1:
152+
return side == ListSide.Left ? LPushX(context, key, elements) : RPushX(context, key, elements);
153+
default:
154+
when.AlwaysOrExists(); // check that "when" is valid
155+
return LLen(context, key); // handle zero case (no insert, just get length)
156+
}
157+
}
158+
127159
[RespCommand]
128160
public static partial RespOperation<long> LPush(this in ListCommands context, RedisKey key, RedisValue[] elements);
129161

@@ -164,7 +196,9 @@ public static partial RespOperation LSet(
164196
public static partial RespOperation<RedisValue[]> RPop(this in ListCommands context, RedisKey key, long count);
165197

166198
[RespCommand]
167-
public static partial RespOperation<RedisValue> RPopLPush(this in ListCommands context, RedisKey source,
199+
public static partial RespOperation<RedisValue> RPopLPush(
200+
this in ListCommands context,
201+
RedisKey source,
168202
RedisKey destination);
169203

170204
[RespCommand]

0 commit comments

Comments
 (0)