0

I have a single Redis server running on a Windows 2008 machine. I have multiple websites that each use the BasicRedisClientManager. This instance is setup once on app start and set in into the Application[] store. That way it's reusable across all users. The problem I am having is that one site runs on a dedicated server and the other sites run on localhost where the Redis server is running. One is production and the others are test locations for new work/demonstration. The remote client works just fine but the localhost clients will not communicate with the server and seem to be in a locked/dead state. When I run the site I just get a stack overflow and the site recycles itself. Below is some sample code of the setup I have. I see there is some information on creating locks amongst clients but I'm not sure if this is the route I need to take.

http://www.servicestack.net/docs/redis-client/distributed-locking-with-redis

Sample Code:

    protected override void Application_Start(object sender, EventArgs e)
    {
        /*
         * Create basicRedisClientManager for redis.
         */
        var redisHost = ConfigurationManager.AppSettings["RedisHostIp"].ToString();
        BasicRedisClientManager basicRedisClientManager = new BasicRedisClientManager(redisHost);
        Application["BasicRedisClientManager"] = basicRedisClientManager;

     .....
    }

Then it's use in class constructor

    public CacheManager()
    {
        if (Application["BasicRedisClientManager"] != null)
        {
            /*local variable*/
            basicRedisClientManager = (BasicRedisClientManager)Application["BasicRedisClientManager"];
        }
    }

Within class using the manager.

        if (basicRedisClientManager != null)
        {
            using (var redisClient = (RedisClient)basicRedisClientManager.GetClient())
            {
                if (!saveToInProcOnly && redisClient != null)
                {
                    using (var redis = redisClient.GetTypedClient<T>())
                    {
                        redis.SetEntry(key, value);
                    }
                }
            }
        }

This logic is the same across all sites.

Any insight is much appreciated!

Mike Bailey
  • 12,479
  • 14
  • 66
  • 123
Mark Tomlinson
  • 117
  • 1
  • 11

1 Answers1

1

I don't know BasicRedisClientManager but I recommend you to use BookSleeve client library. With regards to connection reuse, the answer is don't reuse. That is, recreate the connection every time you need it, as BookSleeve's author recommends.

Please see this question and the accepted answer to see how to create bullet-proof Redis client connection.

Community
  • 1
  • 1
Ofer Zelig
  • 17,068
  • 9
  • 59
  • 93
  • Sorry for the delay but we cannot use book sleeve as it requires .net4. I have to believe that there is an answer to this other than just use book sleeve. Am i not implementing it right to connect to Redis from multiple websites? I would think a new client would spin up from my second site instance and use that client for communication. – Mark Tomlinson Jun 19 '12 at 17:56