diff --git a/NadekoBot.Core/Modules/Searches/Services/SearchesService.cs b/NadekoBot.Core/Modules/Searches/Services/SearchesService.cs index 6876dfea..2755cfb1 100644 --- a/NadekoBot.Core/Modules/Searches/Services/SearchesService.cs +++ b/NadekoBot.Core/Modules/Searches/Services/SearchesService.cs @@ -53,10 +53,28 @@ namespace NadekoBot.Modules.Searches.Services private readonly ConcurrentDictionary> _blacklistedTags = new ConcurrentDictionary>(); private readonly Timer _t; + private readonly SemaphoreSlim _cryptoLock = new SemaphoreSlim(1, 1); public async Task CryptoData() { - var data = await _cache.Redis.GetDatabase() - .StringGetAsync("crypto_data").ConfigureAwait(false); + string data; + var r = _cache.Redis.GetDatabase(); + await _cryptoLock.WaitAsync().ConfigureAwait(false); + try + { + data = await r.StringGetAsync("crypto_data").ConfigureAwait(false); + + if (data == null) + { + data = await Http.GetStringAsync("https://api.coinmarketcap.com/v1/ticker/") + .ConfigureAwait(false); + + await r.StringSetAsync("crypto_data", data, TimeSpan.FromHours(6)).ConfigureAwait(false); + } + } + finally + { + _cryptoLock.Release(); + } return JsonConvert.DeserializeObject(data); } @@ -121,14 +139,7 @@ namespace NadekoBot.Modules.Searches.Services var r = _cache.Redis.GetDatabase(); try { - var data = (string)(await r.StringGetAsync("crypto_data").ConfigureAwait(false)); - if (data == null) - { - data = await Http.GetStringAsync("https://api.coinmarketcap.com/v1/ticker/") - .ConfigureAwait(false); - - await r.StringSetAsync("crypto_data", data, TimeSpan.FromHours(6)).ConfigureAwait(false); - } + } catch (Exception ex) {