1. 程式人生 > >用Redis實現Session功能

用Redis實現Session功能

static Managers()
        {
            string sessionRedis= ConfigurationManager.AppSettings["SessionRedis"];
            string timeOut = ConfigurationManager.AppSettings["SessionRedisTimeOut"];

            if (string.IsNullOrEmpty(sessionRedis))
            {
                throw new Exception("
web.config 缺少配置SessionRedis,每臺Redis之間用,分割.第一個必須為主機"); } if (string.IsNullOrEmpty(timeOut)==false) { TimeOut = Convert.ToInt32(timeOut); } var host = sessionRedis.Split(char.Parse(",")); var writeHost = new string
[] { host[0] }; var readHosts = host.Skip(1).ToArray(); ClientManagers = new PooledRedisClientManager(writeHost, readHosts, new RedisClientManagerConfig { MaxWritePoolSize = writeReadCount,//“寫”連結池連結數 MaxReadPoolSize = writeReadCount,//
“讀”連結池連結數 AutoStart = true }); }