locked
How to implement Redis Cluster for SignalR scaleout RRS feed

  • Question

  • User1135166864 posted

    Hey guys,

    we implement our SignalR project with Redis for Scaleout, but now we've met a seriously issue which is that our IT department won't allow our Signal Point of Failure(SPOF), so we make a decision to implement Redis cluster for our production environment.

    So my question is how to implement the Redis Cluster for our project.

    Do we just need to configure the Redis server, no need to update the application codes or we also need to update server code for cluster, I saw our mongoDB configuration node is "server1,server2", Does the Redis cluster is the same with mongoDB ?

    here is our Startup Codes for Redis Scaleout:

      public void Configuration(IAppBuilder app)
            {
                GlobalHost.DependencyResolver.Register(
                    typeof (CheckInHub),
                    () => new CheckInHub(new CheckInHubManager()));
                GlobalHost.DependencyResolver.Register(
                    typeof (CoordinatorHub),
                    () => new CoordinatorHub());
                try
                {
                    var option = ConfigUtil.GetAppSetting("SignalR.Scaleout.Option");
                    switch (option)
                    {
                        case "Redis":   // the optimizest scaleout solution for SignalR performance
                            var redisHost = ConfigUtil.GetAppSetting("SignalR.Redis.Host");
                            var redisPort = Convert.ToInt32(ConfigUtil.GetAppSetting("SignalR.Redis.Port"));
                            var redisPassword = ConfigUtil.GetAppSetting("SignalR.Redis.Password");
                            var redisEventKey = ConfigUtil.GetAppSetting("SignalR.Redis.EventKey");
                            var redisconfig = new RedisScaleoutConfiguration(redisHost, redisPort, redisPassword, redisEventKey)
                            {
                                MaxQueueLength = Convert.ToInt32(ConfigUtil.GetAppSetting("SignalR.Scaleout.MaxQueueLength")),
                            };
                            GlobalHost.DependencyResolver.UseRedis(redisconfig);
                            break;

                        case "Sqlserver": // the second scaleout solution for SignalR performance
                            var sqlConnectionString = ConfigUtil.GetAppSetting("SignalR");
                            var sqlconfig = new SqlScaleoutConfiguration(sqlConnectionString)
                            {
                                TableCount = Convert.ToInt32(ConfigUtil.GetAppSetting("SignalR.Scaleout.TableCount")),
                                MaxQueueLength = Convert.ToInt32(ConfigUtil.GetAppSetting("SignalR.Scaleout.MaxQueueLength")),
                            };
                            GlobalHost.DependencyResolver.UseSqlServer(sqlconfig);
                            break;

                        default:  // default scalueout solution, we use Redis to improve the SignalR performance
                            var defaultHost = ConfigUtil.GetAppSetting("SignalR.Redis.Host");
                            var defaultPort = Convert.ToInt32(ConfigUtil.GetAppSetting("Redis.Port"));
                            var defaultPassword = ConfigUtil.GetAppSetting("SignalR.Redis.Password");
                            var defaultEventKey = ConfigUtil.GetAppSetting("SignalR.Redis.EventKey");

                            var defaultconfig = new RedisScaleoutConfiguration(defaultHost, defaultPort, defaultPassword,
                                defaultEventKey)
                            {
                                MaxQueueLength = Convert.ToInt32(ConfigUtil.GetAppSetting("SignalR.Scaleout.MaxQueueLength")),
                            };
                            GlobalHost.DependencyResolver.UseRedis(defaultconfig);
                            break;
                    }
                    app.Map("/signalr", map =>
                    {
                        map.UseCors(CorsOptions.AllowAll);
                        var hubConfiguration = new HubConfiguration
                        {
                            EnableDetailedErrors = true,
                            EnableJavaScriptProxies = true
                        };
                        map.RunSignalR(hubConfiguration);
                    });
                }
                catch (Exception exception)
                {
                    Logger.Write(0, 0, MessageType.CheckinTeacher, Application.CheckinTeacher, Severity.Fatal, exception.Message, exception.StackTrace);
                }
            }

    Saturday, October 10, 2015 12:45 AM

All replies