0

I am trying to connect to Azure Redis cache using StackExchange.Redis.StrongName V1.2.1

My code looks like this

string redisServer = ConfigManager.GetValue("RedisServer");
redis = ConnectionMultiplexer.Connect(redisServer);
redisDB = redis.GetDatabase();          
var serializedValue = redisDB.StringGet(key);

The last line always throws this exception

{"Access to the registry key '238' is denied."}

at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) at Microsoft.Win32.RegistryKey.InternalGetValue(String name, Object defaultValue, Boolean doNotExpand, Boolean checkSecurity) at Microsoft.Win32.RegistryKey.GetValue(String name) at System.Diagnostics.PerformanceMonitor.GetData(String item) at System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item) at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String category) at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String machine, String category) at System.Diagnostics.PerformanceCounter.NextSample() at System.Diagnostics.PerformanceCounter.NextValue() at StackExchange.Redis.PerfCounterHelper.TryGetSystemCPU(Single& value)
at StackExchange.Redis.ConnectionMultiplexer.GetSystemCpuPercent()
at StackExchange.Redis.ConnectionMultiplexer.GetThreadPoolAndCPUSummary() at StackExchange.Redis.ExceptionFactory.NoConnectionAvailable(Boolean includeDetail, RedisCommand command, Message message, ServerEndPoint server, ServerEndPoint[] serverSnapshot) at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor1 processor, ServerEndPoint server) at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor1 processor, ServerEndPoint server) at StackExchange.Redis.RedisDatabase.StringGet(RedisKey key, CommandFlags flags) at CacheManager.Get[T](String key)

The same code works just fine when using a local Redis cache server.

Any suggestion how to fix this issues?

Emad Gabriel
  • 3,677
  • 7
  • 37
  • 49

2 Answers2

0

According to your description, I have tested this issue by creating a console application and a web application which both target on .NET framework 4.5 by referencing StackExchange.Redis 1.2.1 or StackExchange.Redis.StrongName 1.2.1 to set/get key values from Azure Redis Cache, it could work as expected on my side.

The same code works just fine when using a local Redis cache server.

Based on your code, the exception was thrown by IDatabase.StringGet, I assumed that you could try to check with your Azure Redis Cache connectionstring and follow the official tutorial about connecting to Azure Redis Cache. Or you could provide more details (e.g. your hosting environment, etc.) about your scenario, then we could better help you to locate and solve this issue.

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35
0

The interesting part of this callstack is here:

StackExchange.Redis.PerfCounterHelper.TryGetSystemCPU(Single& value)

The above code is trying to instantiate a PerformanceCounter object so that it can query the local system's CPU usage. Last I checked, that code caught all exceptions because it knows that some environments don't allow you to create PerformanceCounters. That exception shouldn't bubble up to your application. If that exception is bubbling up to your app layer, then this would be a regression in StackExchange.Redis and a fix should be submitted there.

JonCole
  • 2,902
  • 1
  • 17
  • 19
  • BTW, here is the code for TryGetSystemCPU: https://github.com/StackExchange/StackExchange.Redis/blob/master/StackExchange.Redis/StackExchange/Redis/DebuggingAids.cs#L308 – JonCole Mar 15 '17 at 21:30