7

Redis セッション状態プロバイダーを Web アプリケーションに実装しましたが、魅力的に機能しますが、redis サーバーに障害が発生したり、Web サーバーが redis サーバーに接続できなかったりするとどうなるでしょうか。

InProc セッション状態管理を Redis のフェイルオーバーとして使用する方法はありますか? 複数のセッション状態プロバイダーの宣言に関するドキュメントが見つからないため、redis が失敗した場合でも、システムは inproc を使用して引き続き作業できます。(redis でセッション状態を失い、失敗した場合はゼロから開始し、inproc で再びセッション状態を失い、redis が利用可能になった場合はゼロから開始することを受け入れます)

4

3 に答える 3

-1

私は StackExchange ライブラリを使用して redis サーバーに接続しています。これは、イベントをサブスクライブする方法を示すだけの単純なコードであり、最終的な解決策ではありません。センチネルが新しいサーバーを選択するたびに、そのイベントを受け取るので、新しいサーバーを選択します。

ConnectionMultiplexer multiplexer =
   ConnectionMultiplexer.Connect(new ConfigurationOptions
   {
       CommandMap = CommandMap.Sentinel,
       EndPoints = { { "127.0.0.1", 26379 }, { "127.0.0.1", 26380 } },
       AllowAdmin = true,
       TieBreaker = "",
       ServiceName = "mymaster",
       SyncTimeout = 5000
   }); 
    multiplexer.GetSubscriber().Subscribe("*", (c, m) =>
        {

            Debug.WriteLine("the message=" + m);
            Debug.WriteLine("channel=" + c);

            try
            {
                var sentinelServer = multiplexer.GetServer("127.0.0.1", 26379).SentinelGetMasterAddressByName("mymaster");
                Debug.WriteLine("Current server=" + sentinelServer);
                Debug.Flush();
            }
            catch (Exception)
            {
                var sentinelServer = multiplexer.GetServer("127.0.0.1", 26380).SentinelGetMasterAddressByName("mymaster");
                Debug.WriteLine("Current server=" + sentinelServer );
                Debug.Flush();
            }
        });
于 2015-09-04T07:18:50.047 に答える