Search code examples
redisappharborbooksleeve

Redis on Appharbor - Booksleeve GetString exception


i am trying to setup Redis on appharbor. I have followed their instructions and again i have an issue with the Booksleeve API. Here is the code i am using to make it work initially:

               var connectionUri = new Uri(url);

                using (var redis = new RedisConnection(connectionUri.Host, connectionUri.Port, password: connectionUri.UserInfo.Split(new[] { ':' }, 2)[1]))
                {
                    redis.Strings.Set(1, "greeting", "welcome to remember your stuff!");

                    try
                    {
                        var task = redis.Strings.GetString(1, "greeting");

                        redis.Wait(task);

                        ViewBag.Message = task.Result;
                    }
                    catch (Exception)
                    {
                        // It throws an exception trying to wait for the task?
                    }
                }

However, the issue is that it sets the string correctly, but when trying to retrieve the same string from the key value store, it throws a timeout exception waiting for the task to eexecute. However, this code works on my local redis server connection.

Am i using the API in a wrong way? or is this something related to Appharbor?

Thanks


Solution

  • Like a SqlConnection, you need to call Open() (otherwise your messages are queued for delivery).

    Unlike SqlConnection, you should not fire up a RedisConnection each time you need it - it is intended to be used as a shared, thread-safe, multiplexer - i.e. a single connection is held somewhere and used by lots and lots of unrelated callers. Unless of course you only need to do one thing!