1

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

Faris Zacina
  • 14,056
  • 7
  • 62
  • 75

1 Answers1

1

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!

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Thanks for the quick response and hints!..The connection now works. It goes over the wait line. but for some reason on the task.Result line i get the following: // Error processing data: A critical operation failed: 1: SELECT.. is this an appharbor redis issue?.. i could get the data on my local server? – Faris Zacina Apr 27 '12 at 16:51
  • 2
    @DoubleScorpio do you have 2 databases? Databases are 0-based; if you only have 1, use DB 0. – Marc Gravell Apr 27 '12 at 17:05
  • i set to DB 0 and It Works!!!.. thanks for your help!.. i was just playing around with the client, but now that it works i will restructure my code and build something good with it :).. Thanks again! – Faris Zacina Apr 27 '12 at 17:11
  • @DoubleScorpio - the number of DBs is a server configuration option, btw – Marc Gravell Apr 27 '12 at 18:31