Skip to content

Improves Redis operations resilience#108

Merged
niemyjski merged 1 commit intomainfrom
feature/resilience
Aug 8, 2025
Merged

Improves Redis operations resilience#108
niemyjski merged 1 commit intomainfrom
feature/resilience

Conversation

@niemyjski
Copy link
Copy Markdown
Member

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.

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.
@niemyjski niemyjski requested review from Copilot and ejsmith August 8, 2025 16:35
@niemyjski niemyjski self-assigned this Aug 8, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.WithRetriesAsync calls with _resiliencePolicy.ExecuteAsync across Redis operations
  • Adds IResiliencePolicy field to Redis classes and initializes it from options
  • Introduces AnyContext extension methods for ValueTask and ValueTask<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();
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copilot uses AI. Check for mistakes.
@niemyjski niemyjski merged commit 1417f98 into main Aug 8, 2025
3 of 4 checks passed
@niemyjski niemyjski deleted the feature/resilience branch August 8, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants