Skip to content

Commit 77b8a97

Browse files
committed
PG-251 Simplify getting the end of the list
1 parent 81759a6 commit 77b8a97

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

src/Learning.MessageQueue/Repository/MessageQueueRepository.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,7 @@ public async Task<RetryData> GetRetryData(IMessage @event)
100100
public async Task<RedisValue[]> GetOldestProcessingEvents<T>(int count) where T : IMessage
101101
{
102102
var processingEventsListKey = GetProcessingEventsListKey<T>();
103-
var listLength = await _redisClient.ListLengthAsync(processingEventsListKey).ConfigureAwait(false);
104-
long startIndex;
105-
106-
if (listLength == 0)
107-
{
108-
return new RedisValue[0];
109-
}
110-
if (listLength > count)
111-
{
112-
startIndex = listLength - count;
113-
}
114-
else
115-
{
116-
startIndex = 0;
117-
}
118-
119-
var unprocessedEvents = await _redisClient.ListRangeAsync(processingEventsListKey, startIndex, -1).ConfigureAwait(false);
103+
var unprocessedEvents = await _redisClient.ListRangeAsync(processingEventsListKey, count * -1, -1).ConfigureAwait(false);
120104
return unprocessedEvents;
121105
}
122106

@@ -126,10 +110,11 @@ public async Task MoveProcessingEventToDeadLetterQueue<T>(RedisValue eventData,
126110
var processingEventsListKey = GetProcessingEventsListKey<T>();
127111
var tran = _redisClient.CreateTransaction();
128112

129-
tran.ListLeftPushAsync(deadLetterListKey, eventData);
130-
tran.ListRemoveAsync(processingEventsListKey, eventData, -1);
113+
var pushTask = tran.ListLeftPushAsync(deadLetterListKey, eventData);
114+
var removeTask = tran.ListRemoveAsync(processingEventsListKey, eventData, -1);
131115

132116
await ExcecuteTransaction(tran, @event.Id).ConfigureAwait(false);
117+
await Task.WhenAll(pushTask, removeTask).ConfigureAwait(false);
133118
}
134119

135120
private string GetDeadLetterListKey<T>() where T : IMessage

0 commit comments

Comments
 (0)