Ejemplo n.º 1
0
        private bool ConnectToRedis()
        {
            var redisDB = MasterServerSettings.Default.RedisDB.Trim();
            if (string.IsNullOrWhiteSpace(redisDB))
            {
                log.InfoFormat("Application {0}/{1} starts without Redis", this.ApplicationId, this.Version);
                return false;
            }

            PooledRedisClientManager manager = null;
            try
            {
                manager = new PooledRedisClientManager(redisDB);
                using (var client = manager.GetDisposableClient<RedisClient>())
                {
                    client.Client.Ping();
                }

                this.redisManager = manager;
            }
            catch (Exception e)
            {
                if (manager != null)
                {
                    manager.Dispose();
                }
                log.WarnFormat("Exception through connection to redis at '{0}'. Will continue without Redis", redisDB);
                log.WarnFormat("Exception: {0}", e);

                return false;
            }
            return true;
        }