Skip to content

Commit 920ba0d

Browse files
committed
Fix test
1 parent 2323c14 commit 920ba0d

File tree

2 files changed

+12
-45
lines changed

2 files changed

+12
-45
lines changed

libs/server/Resp/RespServerSession.cs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,43 +1188,6 @@ ReadOnlySpan<byte> GetUpperCaseCommand(out bool success)
11881188
return result;
11891189
}
11901190

1191-
public ArgSlice GetCommandAsArgSlice(out bool success)
1192-
{
1193-
if (bytesRead - readHead < 6)
1194-
{
1195-
success = false;
1196-
return default;
1197-
}
1198-
1199-
Debug.Assert(*(recvBufferPtr + readHead) == '$');
1200-
int psize = *(recvBufferPtr + readHead + 1) - '0';
1201-
readHead += 2;
1202-
while (*(recvBufferPtr + readHead) != '\r')
1203-
{
1204-
psize = psize * 10 + *(recvBufferPtr + readHead) - '0';
1205-
if (bytesRead - readHead < 1)
1206-
{
1207-
success = false;
1208-
return default;
1209-
}
1210-
readHead++;
1211-
}
1212-
if (bytesRead - readHead < 2 + psize + 2)
1213-
{
1214-
success = false;
1215-
return default;
1216-
}
1217-
Debug.Assert(*(recvBufferPtr + readHead + 1) == '\n');
1218-
1219-
var result = new ArgSlice(recvBufferPtr + readHead + 2, psize);
1220-
Debug.Assert(*(recvBufferPtr + readHead + 2 + psize) == '\r');
1221-
Debug.Assert(*(recvBufferPtr + readHead + 2 + psize + 1) == '\n');
1222-
1223-
readHead += 2 + psize + 2;
1224-
success = true;
1225-
return result;
1226-
}
1227-
12281191
/// <summary>
12291192
/// Attempt to kill this session.
12301193
///

libs/server/Transaction/TxnKeyManager.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private int ListObjectKeys(RespCommand command)
396396
RespCommand.LSET => SingleKey(StoreType.Object, LockType.Exclusive),
397397

398398
RespCommand.LMOVE => ListKeys(2, StoreType.Object, LockType.Exclusive),
399-
RespCommand.LMPOP => ListReadKeysWithCount(LockType.Exclusive),
399+
RespCommand.LMPOP => ListReadKeysWithCount(LockType.Exclusive, mandatoryArgs: 1),
400400
RespCommand.LPOS => SingleKey(StoreType.Object, LockType.Shared),
401401
RespCommand.LPUSHX => SingleKey(StoreType.Object, LockType.Exclusive),
402402
RespCommand.RPOPLPUSH => ListKeys(2, StoreType.Object, LockType.Exclusive),
@@ -498,17 +498,21 @@ private int ListKeys(int inputCount, StoreType storeType, LockType type)
498498
/// <summary>
499499
/// Returns a list of keys for LMPOP command
500500
/// </summary>
501-
private int ListReadKeysWithCount(LockType type, bool isObject = true)
501+
private int ListReadKeysWithCount(LockType type, bool isObject = true, int mandatoryArgs = 0)
502502
{
503-
var numKeysArg = respSession.GetCommandAsArgSlice(out var success);
504-
if (!success) return -2;
503+
if (respSession.parseState.Count == 0)
504+
return -2;
505+
var numKeysArg = respSession.parseState.GetArgSliceByRef(0);
505506

506-
if (!NumUtils.TryParse(numKeysArg.ReadOnlySpan, out int numKeys)) return -2;
507+
if (!NumUtils.TryParse(numKeysArg.ReadOnlySpan, out int numKeys))
508+
return -2;
507509

508-
for (var i = 0; i < numKeys; i++)
510+
if (numKeys + mandatoryArgs + 1 > respSession.parseState.Count)
511+
return -2;
512+
513+
for (var i = 1; i < numKeys + 1; i++)
509514
{
510-
var key = respSession.GetCommandAsArgSlice(out success);
511-
if (!success) return -2;
515+
var key = respSession.parseState.GetArgSliceByRef(i);
512516
SaveKeyEntryToLock(key, isObject, type);
513517
SaveKeyArgSlice(key);
514518
}

0 commit comments

Comments
 (0)