Azure-Samples / azure-cache-redis-samples

This repository contains samples that demonstrate best practices and general recommendations to communicate with Azure Redis Cache Service caches from various Redis client frameworks.
MIT License
69 stars 156 forks source link

Move away from Lazy<ConnectionMultiplexer> and use SemaphoreSlim, Async #13

Closed amsoedal closed 3 years ago

amsoedal commented 3 years ago

Purpose

It's been pointed out to us by several sources that the Lazy pattern can lead to lock contention & thread starvation. To avoid this, I've replaced this pattern with an explicit singleton initialization. I also updated the code to use SemaphoreSlim instead of Locks for performance, and to take advantage of the async overloads from StackExchange.Redis.

Pull Request Type

What kind of change does this Pull Request introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

Other Information

N/A