Skip to content

Instantly share code, notes, and snippets.

@Plasma
Last active August 29, 2015 14:05
Show Gist options
  • Save Plasma/62f9e3a2010ed1a6e486 to your computer and use it in GitHub Desktop.
Save Plasma/62f9e3a2010ed1a6e486 to your computer and use it in GitHub Desktop.
StackExchange.Redis TIMEOUT Exception example
// Raises Exception:
// Timeout performing INCR TestRedisKey, inst: 12, queue: 2, qu=0, qs=2, qc=0, wr=0/0, in=5/1
// Note: await Task.Yield() after ConnectAsync fixes the problem, as does Connect() vs ConnectAsync().
// Program.cs
using System;
using System.Linq;
using System.Threading.Tasks;
using StackExchange.Redis;
namespace StackExchangeTest
{
class Program
{
static void Main(string[] args)
{
// Execute
var task = RunAsync();
// Wait
try {
task.Wait();
} catch (AggregateException ae) {
throw ae.InnerExceptions.Single();
}
}
static async Task RunAsync()
{
// Open Connection
Console.WriteLine("Connecting...");
var configurationOptions = ConfigurationOptions.Parse("127.0.0.1");
// Connect Async
var connection = await ConnectionMultiplexer.ConnectAsync(configurationOptions);
if (!connection.IsConnected)
throw new ArgumentException("Failed to connect during test case");
// Attempt Increment
Console.WriteLine("Connection to Redis established");
var result = connection.GetDatabase().StringIncrement("TestRedisKey");
Console.WriteLine("Incr() with value: {0} (test succeeded in time without error)", result);
Console.WriteLine("Finished");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment