Conversation
Replaces Run.WithRetriesAsync with a resilience policy for Redis operations to improve stability and handle transient errors. Introduces AnyContext extension methods for ValueTask and Task types to avoid deadlocks.
There was a problem hiding this comment.
Pull Request Overview
This PR replaces manual retry logic with a formal resilience policy for Redis operations to improve error handling and stability. It also introduces extension methods for ValueTask types to prevent potential deadlocks.
- Replaces
Run.WithRetriesAsynccalls with_resiliencePolicy.ExecuteAsyncacross Redis operations - Adds
IResiliencePolicyfield to Redis classes and initializes it from options - Introduces
AnyContextextension methods forValueTaskandValueTask<T>types
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Foundatio.Redis/Storage/RedisFileStorage.cs | Replaces retry logic with resilience policy for file storage operations |
| src/Foundatio.Redis/Queues/RedisQueue.cs | Updates queue operations to use resilience policy instead of manual retries |
| src/Foundatio.Redis/Messaging/RedisMessageBus.cs | Applies resilience policy to message publishing operations |
| src/Foundatio.Redis/Extensions/TaskExtensions.cs | Adds AnyContext extension methods for ValueTask types |
| var enqueuedTimeTicks = Run.WithRetriesAsync(() => _cache.GetAsync<long>(GetEnqueuedTimeKey(workId), 0), logger: _logger); | ||
| var attemptsValue = Run.WithRetriesAsync(() => _cache.GetAsync(GetAttemptsKey(workId), 0), logger: _logger); | ||
| var enqueuedTimeTicks = _resiliencePolicy.ExecuteAsync(async _ => await _cache.GetAsync<long>(GetEnqueuedTimeKey(workId), 0)).AsTask(); | ||
| var attemptsValue = _resiliencePolicy.ExecuteAsync(async _ => await _cache.GetAsync(GetAttemptsKey(workId), 0)).AsTask(); |
There was a problem hiding this comment.
Same issue as the previous line - the .AsTask() call appears to be incorrectly placed. The resilience policy likely returns a ValueTask, so you should either await the ValueTask directly or call .AsTask() on the ValueTask itself, not on the entire expression.
Suggested change
| var attemptsValue = _resiliencePolicy.ExecuteAsync(async _ => await _cache.GetAsync(GetAttemptsKey(workId), 0)).AsTask(); | |
| var attemptsValue = (_resiliencePolicy.ExecuteAsync(async _ => await _cache.GetAsync(GetAttemptsKey(workId), 0))).AsTask(); |
niemyjski
commented
Aug 8, 2025
niemyjski
commented
Aug 8, 2025
ejsmith
approved these changes
Aug 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces Run.WithRetriesAsync with a resilience policy for Redis operations to improve stability and handle transient errors.
Introduces AnyContext extension methods for ValueTask and Task types to avoid deadlocks.