|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Configuration;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace Senparc.Weixin.Cache.Redis
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// Redis配置信息
|
|
|
/// </summary>
|
|
|
public sealed class RedisConfigInfo : ConfigurationSection
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取配置信息,默认配置节点名称为RedisConfig
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static RedisConfigInfo GetConfig()
|
|
|
{
|
|
|
RedisConfigInfo section = (RedisConfigInfo)ConfigurationManager.GetSection("RedisConfig");
|
|
|
return section;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取配置信息
|
|
|
/// </summary>
|
|
|
/// <param name="sectionName">配置节点的sectionName</param>
|
|
|
/// <returns></returns>
|
|
|
public static RedisConfigInfo GetConfig(string sectionName)
|
|
|
{
|
|
|
RedisConfigInfo section = (RedisConfigInfo)ConfigurationManager.GetSection(sectionName);
|
|
|
if (section == null)
|
|
|
throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
|
|
|
return section;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 可写的Redis链接地址
|
|
|
/// </summary>
|
|
|
[ConfigurationProperty("WriteServerList", IsRequired = false)]
|
|
|
public string WriteServerList
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return (string)base["WriteServerList"];
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
base["WriteServerList"] = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 可读的Redis链接地址
|
|
|
/// </summary>
|
|
|
[ConfigurationProperty("ReadServerList", IsRequired = false)]
|
|
|
public string ReadServerList
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return (string)base["ReadServerList"];
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
base["ReadServerList"] = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 最大写链接数
|
|
|
/// </summary>
|
|
|
[ConfigurationProperty("MaxWritePoolSize", IsRequired = false, DefaultValue = 5)]
|
|
|
public int MaxWritePoolSize
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
int _maxWritePoolSize = (int)base["MaxWritePoolSize"];
|
|
|
return _maxWritePoolSize > 0 ? _maxWritePoolSize : 5;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
base["MaxWritePoolSize"] = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 最大读链接数
|
|
|
/// </summary>
|
|
|
[ConfigurationProperty("MaxReadPoolSize", IsRequired = false, DefaultValue = 5)]
|
|
|
public int MaxReadPoolSize
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
int _maxReadPoolSize = (int)base["MaxReadPoolSize"];
|
|
|
return _maxReadPoolSize > 0 ? _maxReadPoolSize : 5;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
base["MaxReadPoolSize"] = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 自动重启
|
|
|
/// </summary>
|
|
|
[ConfigurationProperty("AutoStart", IsRequired = false, DefaultValue = true)]
|
|
|
public bool AutoStart
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return (bool)base["AutoStart"];
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
base["AutoStart"] = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 本地缓存到期时间,单位:秒
|
|
|
/// </summary>
|
|
|
[ConfigurationProperty("LocalCacheTime", IsRequired = false, DefaultValue = 36000)]
|
|
|
public int LocalCacheTime
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return (int)base["LocalCacheTime"];
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
base["LocalCacheTime"] = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否记录日志,该设置仅用于排查redis运行时出现的问题,如redis工作正常,请关闭该项
|
|
|
/// </summary>
|
|
|
[ConfigurationProperty("RecordeLog", IsRequired = false, DefaultValue = false)]
|
|
|
public bool RecordeLog
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return (bool)base["RecordeLog"];
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
base["RecordeLog"] = value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|