Don't lose Redis connection on reconnect

Keep Redis connection stored so that it's not lost and we avoid
reconnecting all the time.
This commit is contained in:
Ossi Herrala 2017-10-01 17:26:01 +03:00
parent a58579e442
commit c2eeb7ab73

View File

@ -31,7 +31,8 @@ namespace Worker
// Reconnect redis if down // Reconnect redis if down
if (redisConn == null || !redisConn.IsConnected) { if (redisConn == null || !redisConn.IsConnected) {
Console.WriteLine("Reconnecting Redis"); Console.WriteLine("Reconnecting Redis");
redis = OpenRedisConnection("redis").GetDatabase(); redisConn = OpenRedisConnection("redis");
redis = redisConn.GetDatabase();
} }
string json = redis.ListLeftPopAsync("votes").Result; string json = redis.ListLeftPopAsync("votes").Result;
if (json != null) if (json != null)